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

.[](*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

.hashObject



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

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

.search(name, limit = 1) ⇒ Object



35
36
37
# File 'lib/bitshares/asset.rb', line 35

def search name, limit=1
	Rpc.new('list_assets',[name,limit]).send.inject([]) {|m,a| m << Asset.new(a) }
end

Instance Method Details

#to_sObject



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

def to_s
	@name
end