Class: BitShares::Asset
- Inherits:
-
Object
- Object
- BitShares::Asset
- Defined in:
- lib/bitshares/asset.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash) ⇒ Asset
constructor
A new instance of Asset.
- #to_s ⇒ Object
Constructor Details
#initialize(hash) ⇒ Asset
Returns a new instance of Asset.
5 6 7 8 9 10 |
# File 'lib/bitshares/asset.rb', line 5 def initialize hash @id = hash['id'] @name = hash['symbol'] @hash = hash self.class.add self end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/bitshares/asset.rb', line 3 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/bitshares/asset.rb', line 3 def name @name end |
Class Method Details
.[](*ids) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bitshares/asset.rb', line 17 def [] *ids id = ids.first if /^\d\.\d*\.\d*/.match(id) unless hash.key? id arr = RPC.new('get_assets',[[id]]).send.inject([]) {|m,a| m << Asset.new(a) } end (ids.size == 1) ? (hash[ida]) : (arr) else arr = [] hash.each_pair do |k,v| if ids.include? v.name (ids.size == 1) ? (return v) : (arr << v) end end arr end end |
.add(h) ⇒ Object
39 40 41 |
# File 'lib/bitshares/asset.rb', line 39 def add h hash[h.id] = h unless hash.key? h.id end |
.hash ⇒ Object
43 |
# File 'lib/bitshares/asset.rb', line 43 def hash() @h ||= {} end |
Instance Method Details
#to_s ⇒ Object
12 13 14 |
# File 'lib/bitshares/asset.rb', line 12 def to_s @name end |