Class: Bitstamper::Models::Balance
- Defined in:
- lib/bitstamper/models/balance.rb
Instance Attribute Summary collapse
-
#available ⇒ Object
Returns the value of attribute available.
-
#balance ⇒ Object
Returns the value of attribute balance.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#fees ⇒ Object
Returns the value of attribute fees.
-
#reserved ⇒ Object
Returns the value of attribute reserved.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash) ⇒ Balance
constructor
A new instance of Balance.
Methods inherited from Base
Constructor Details
#initialize(hash) ⇒ Balance
Returns a new instance of Balance.
6 7 8 9 10 |
# File 'lib/bitstamper/models/balance.rb', line 6 def initialize(hash) hash.each do |key, value| self.send("#{key}=", value) if self.respond_to?(key) end end |
Instance Attribute Details
#available ⇒ Object
Returns the value of attribute available.
4 5 6 |
# File 'lib/bitstamper/models/balance.rb', line 4 def available @available end |
#balance ⇒ Object
Returns the value of attribute balance.
4 5 6 |
# File 'lib/bitstamper/models/balance.rb', line 4 def balance @balance end |
#currency ⇒ Object
Returns the value of attribute currency.
4 5 6 |
# File 'lib/bitstamper/models/balance.rb', line 4 def currency @currency end |
#fees ⇒ Object
Returns the value of attribute fees.
4 5 6 |
# File 'lib/bitstamper/models/balance.rb', line 4 def fees @fees end |
#reserved ⇒ Object
Returns the value of attribute reserved.
4 5 6 |
# File 'lib/bitstamper/models/balance.rb', line 4 def reserved @reserved end |
Class Method Details
.parse(hash) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/bitstamper/models/balance.rb', line 12 def self.parse(hash) parsed = [] groups = {} hash.each do |key, value| if key !~ /_fee$/i splitted = key.split("_") if splitted.size == 2 currency = splitted.first value_key = splitted.last groups[currency] ||= {} groups[currency][value_key] = value&.to_f end end end hash.each do |key, value| if key =~ /_fee$/i pair = key.split("_")&.first #btceur_fee -> btceur groups.keys.each do |grouped_key| if pair =~ /^#{grouped_key}/i quote_key = pair.gsub(grouped_key, "") groups[grouped_key]["fees"] ||= {} groups[grouped_key]["fees"][quote_key] = value&.to_f end end end end groups = groups.deep_symbolize_keys groups.each do |key, values| values[:currency] = key.to_s.upcase parsed << ::Bitstamper::Models::Balance.new(values) end return parsed end |