Class: BitShares::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/bitshares/asset.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/bitshares/asset.rb', line 3

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/bitshares/asset.rb', line 3

def name
  @name
end

Class Method Details

.[](id) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/bitshares/asset.rb', line 17

def [] id
  if /^\d\.\d*\.\d*/.match(id)
    BitShares.assets id unless hash.key? id
    hash[id] 
  else
    hash.each_pair do |k,v|
      return v if v.name == id
    end
  end
end

.add(h) ⇒ Object



28
29
30
# File 'lib/bitshares/asset.rb', line 28

def add h
  hash[h.id] = h unless hash.key? h.id
end

.hashObject



32
# File 'lib/bitshares/asset.rb', line 32

def hash() @h ||= {} end

Instance Method Details

#to_sObject



12
13
14
# File 'lib/bitshares/asset.rb', line 12

def to_s
  @name
end