Class: OpenCoinage::Currency
- Inherits:
-
Object
- Object
- OpenCoinage::Currency
- Defined in:
- lib/opencoinage/currency.rb
Overview
A digital currency contract.
Constant Summary
- RDF_TYPE =
Vocabulary[:Currency]
Instance Attribute Summary (collapse)
-
- (Issuer) issuer
The issuer of this currency.
-
- (String) name
The name of this currency.
-
- (RDF::URI) uri
(also: #to_uri)
readonly
The URI identifying this currency.
Instance Method Summary (collapse)
-
- (Currency) initialize(uri = nil, options = {})
constructor
Initializes the currency.
-
- (Hash) to_hash
Returns the hash table representation of this currency.
-
- (String) to_json
Returns the JSON representation of this currency.
-
- (RDF::Graph) to_rdf(options = {})
Returns the RDF representation of this currency.
Constructor Details
- (Currency) initialize(uri = nil, options = {})
Initializes the currency.
17 18 19 20 21 |
# File 'lib/opencoinage/currency.rb', line 17 def initialize(uri = nil, = {}) @uri = RDF::URI(uri || UUID.generate(:urn)) @name = [:name] if .has_key?(:name) @issuer = [:issuer] if .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.
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.
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.
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.
71 72 73 74 75 76 77 |
# File 'lib/opencoinage/currency.rb', line 71 def to_rdf( = {}) RDF::Graph.new([: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 |