Class: Bitstamper::Models::Transaction
- Defined in:
- lib/bitstamper/models/transaction.rb
Constant Summary collapse
- TYPES =
{ 0 => :buy, 1 => :sell }
- MAPPING =
{ "id" => :string, "type" => :integer, "date" => :time, "price" => :float, "amount" => :float, }
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#date ⇒ Object
Returns the value of attribute date.
-
#id ⇒ Object
Returns the value of attribute id.
-
#price ⇒ Object
Returns the value of attribute price.
-
#transaction_type ⇒ Object
Returns the value of attribute transaction_type.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash) ⇒ Transaction
constructor
A new instance of Transaction.
Methods inherited from Base
Constructor Details
#initialize(hash) ⇒ Transaction
Returns a new instance of Transaction.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bitstamper/models/transaction.rb', line 19 def initialize(hash) hash.each do |key, value| type = ::Bitstamper::Models::Transaction::MAPPING.fetch(key, nil) value = value && type ? ::Bitstamper::Utilities::convert_value(value, type) : value self.send("#{key}=", value) if self.respond_to?(key) end self.id = hash.fetch("id", hash.fetch("tid", nil))&.to_s self.transaction_type = TYPES[self.type] end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
4 5 6 |
# File 'lib/bitstamper/models/transaction.rb', line 4 def amount @amount end |
#date ⇒ Object
Returns the value of attribute date.
4 5 6 |
# File 'lib/bitstamper/models/transaction.rb', line 4 def date @date end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/bitstamper/models/transaction.rb', line 4 def id @id end |
#price ⇒ Object
Returns the value of attribute price.
4 5 6 |
# File 'lib/bitstamper/models/transaction.rb', line 4 def price @price end |
#transaction_type ⇒ Object
Returns the value of attribute transaction_type.
4 5 6 |
# File 'lib/bitstamper/models/transaction.rb', line 4 def transaction_type @transaction_type end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/bitstamper/models/transaction.rb', line 4 def type @type end |
Class Method Details
.parse(data) ⇒ Object
31 32 33 |
# File 'lib/bitstamper/models/transaction.rb', line 31 def self.parse(data) data&.collect { |item| ::Bitstamper::Models::Transaction.new(item) } end |