Class: OpenAssets::Protocol::AssetDefinition
- Inherits:
-
Object
- Object
- OpenAssets::Protocol::AssetDefinition
- Defined in:
- lib/openassets/protocol/asset_definition.rb
Overview
The Definition of Open Asset
Instance Attribute Summary collapse
-
#asset_ids ⇒ Object
Returns the value of attribute asset_ids.
-
#contract_url ⇒ Object
Returns the value of attribute contract_url.
-
#description ⇒ Object
Returns the value of attribute description.
-
#description_mime ⇒ Object
Returns the value of attribute description_mime.
-
#divisibility ⇒ Object
Returns the value of attribute divisibility.
-
#icon_url ⇒ Object
Returns the value of attribute icon_url.
-
#image_url ⇒ Object
Returns the value of attribute image_url.
-
#issuer ⇒ Object
Returns the value of attribute issuer.
-
#link_to_website ⇒ Object
Returns the value of attribute link_to_website.
-
#name ⇒ Object
Returns the value of attribute name.
-
#name_short ⇒ Object
Returns the value of attribute name_short.
-
#type ⇒ Object
Returns the value of attribute type.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.parse_json(json) ⇒ Object
Parse the JSON obtained from the json String, and create a AssetDefinition object.
-
.parse_url(url) ⇒ Object
Parse the JSON obtained from the URL, and create a AssetDefinition object.
Instance Method Summary collapse
- #include_asset_id?(asset_id) ⇒ Boolean
-
#initialize ⇒ AssetDefinition
constructor
A new instance of AssetDefinition.
- #to_hash ⇒ Object
-
#to_json ⇒ Object
Convert Asset Definition to json format.
Constructor Details
#initialize ⇒ AssetDefinition
Returns a new instance of AssetDefinition.
23 24 25 26 27 |
# File 'lib/openassets/protocol/asset_definition.rb', line 23 def initialize @asset_ids = [] @version = '1.0' @divisibility = 0 end |
Instance Attribute Details
#asset_ids ⇒ Object
Returns the value of attribute asset_ids.
9 10 11 |
# File 'lib/openassets/protocol/asset_definition.rb', line 9 def asset_ids @asset_ids end |
#contract_url ⇒ Object
Returns the value of attribute contract_url.
12 13 14 |
# File 'lib/openassets/protocol/asset_definition.rb', line 12 def contract_url @contract_url end |
#description ⇒ Object
Returns the value of attribute description.
14 15 16 |
# File 'lib/openassets/protocol/asset_definition.rb', line 14 def description @description end |
#description_mime ⇒ Object
Returns the value of attribute description_mime.
15 16 17 |
# File 'lib/openassets/protocol/asset_definition.rb', line 15 def description_mime @description_mime end |
#divisibility ⇒ Object
Returns the value of attribute divisibility.
17 18 19 |
# File 'lib/openassets/protocol/asset_definition.rb', line 17 def divisibility @divisibility end |
#icon_url ⇒ Object
Returns the value of attribute icon_url.
19 20 21 |
# File 'lib/openassets/protocol/asset_definition.rb', line 19 def icon_url @icon_url end |
#image_url ⇒ Object
Returns the value of attribute image_url.
20 21 22 |
# File 'lib/openassets/protocol/asset_definition.rb', line 20 def image_url @image_url end |
#issuer ⇒ Object
Returns the value of attribute issuer.
13 14 15 |
# File 'lib/openassets/protocol/asset_definition.rb', line 13 def issuer @issuer end |
#link_to_website ⇒ Object
Returns the value of attribute link_to_website.
18 19 20 |
# File 'lib/openassets/protocol/asset_definition.rb', line 18 def link_to_website @link_to_website end |
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/openassets/protocol/asset_definition.rb', line 11 def name @name end |
#name_short ⇒ Object
Returns the value of attribute name_short.
10 11 12 |
# File 'lib/openassets/protocol/asset_definition.rb', line 10 def name_short @name_short end |
#type ⇒ Object
Returns the value of attribute type.
16 17 18 |
# File 'lib/openassets/protocol/asset_definition.rb', line 16 def type @type end |
#version ⇒ Object
Returns the value of attribute version.
21 22 23 |
# File 'lib/openassets/protocol/asset_definition.rb', line 21 def version @version end |
Class Method Details
.parse_json(json) ⇒ Object
Parse the JSON obtained from the json String, and create a AssetDefinition object. @param
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/openassets/protocol/asset_definition.rb', line 31 def self.parse_json(json) parsed_json = JSON.parse(json) definition = new definition.asset_ids = parsed_json['asset_ids'] definition.name_short = parsed_json['name_short'] definition.name = parsed_json['name'] definition.contract_url = parsed_json['contract_url'] definition.issuer = parsed_json['issuer'] definition.description = parsed_json['description'] definition.description_mime = parsed_json['description_mime'] definition.type = parsed_json['type'] definition.divisibility = parsed_json['divisibility'] definition.link_to_website = parsed_json['link_to_website'] definition.icon_url = parsed_json['icon_url'] definition.image_url = parsed_json['image_url'] definition.version = parsed_json['version'] definition end |
.parse_url(url) ⇒ Object
Parse the JSON obtained from the URL, and create a AssetDefinition object. @param url The URL of Asset Definition.
52 53 54 55 56 57 58 59 |
# File 'lib/openassets/protocol/asset_definition.rb', line 52 def self.parse_url(url) begin parse_json(RestClient.get url, :accept => :json) rescue => e puts e nil end end |
Instance Method Details
#include_asset_id?(asset_id) ⇒ Boolean
61 62 63 64 |
# File 'lib/openassets/protocol/asset_definition.rb', line 61 def include_asset_id?(asset_id) return false if asset_ids.nil? || asset_ids.empty? asset_ids.include?(asset_id) end |
#to_hash ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/openassets/protocol/asset_definition.rb', line 71 def to_hash instance_variables.inject({}) do |result, var| key = var.to_s key.slice!(0) if key.start_with?('@') result.update(key => instance_variable_get(var)) end end |
#to_json ⇒ Object
Convert Asset Definition to json format.
67 68 69 |
# File 'lib/openassets/protocol/asset_definition.rb', line 67 def to_json to_hash.to_json end |