Class: OpenCoinage::Currency

Inherits:
Object
  • Object
show all
Defined in:
lib/opencoinage/currency.rb

Overview

A digital currency contract.

Constant Summary

RDF_TYPE =
Vocabulary[:Currency]

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Currency) initialize(uri = nil, options = {})

Initializes the currency.

Parameters:

  • (RDF::URI, String, #to_s) uri (defaults to: nil)

    a valid URI identifying the currency

  • (Hash{Symbol => Object}) options (defaults to: {})

Options Hash (options):

  • (String) :name — default: nil

    the name of the currency

  • (Issuer) :issuer — default: nil

    the issuer of the currency



17
18
19
20
21
# File 'lib/opencoinage/currency.rb', line 17

def initialize(uri = nil, options = {})
  @uri    = RDF::URI(uri || UUID.generate(:urn))
  @name   = options[:name]   if options.has_key?(:name)
  @issuer = options[:issuer] if options.has_key?(:issuer)
end

Instance Attribute Details

- (Issuer) issuer

The issuer of this currency.



42
43
44
# File 'lib/opencoinage/currency.rb', line 42

def issuer
  @issuer
end

- (String) name

The name of this currency.

Returns:

  • (String)

See Also:



35
36
37
# File 'lib/opencoinage/currency.rb', line 35

def name
  @name
end

- (RDF::URI) uri (readonly) Also known as: to_uri

The URI identifying this currency.

Returns:

  • (RDF::URI)


27
28
29
# File 'lib/opencoinage/currency.rb', line 27

def uri
  @uri
end

Instance Method Details

- (Hash) to_hash

Returns the hash table representation of this currency.

Returns:

  • (Hash)


48
49
50
# File 'lib/opencoinage/currency.rb', line 48

def to_hash
  {:name => name, :issuer => issuer}
end

- (String) to_json

Returns the JSON representation of this currency.



58
59
60
61
# File 'lib/opencoinage/currency.rb', line 58

def to_json
  require 'json' unless defined?(::JSON)
  to_hash.merge(:issuer => issuer.to_uri.to_s).to_json
end

- (RDF::Graph) to_rdf(options = {})

Returns the RDF representation of this currency.

Parameters:

  • (Hash{Symbol => Object}) options (defaults to: {})

Options Hash (options):

  • (RDF::Resource) :context — default: nil

Returns:

  • (RDF::Graph)

See Also:



71
72
73
74
75
76
77
# File 'lib/opencoinage/currency.rb', line 71

def to_rdf(options = {})
  RDF::Graph.new(options[:context]) do |graph|
    graph << [uri, RDF.type, self.class.const_get(:RDF_TYPE)]
    graph << [uri, RDF::FOAF.name, name] if name
    graph << [uri, Vocabulary[:issuer], issuer.to_uri] if issuer
  end
end