Class: Bitstamper::Models::Transaction

Inherits:
Base
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#attributes

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

#amountObject

Returns the value of attribute amount.



4
5
6
# File 'lib/bitstamper/models/transaction.rb', line 4

def amount
  @amount
end

#dateObject

Returns the value of attribute date.



4
5
6
# File 'lib/bitstamper/models/transaction.rb', line 4

def date
  @date
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/bitstamper/models/transaction.rb', line 4

def id
  @id
end

#priceObject

Returns the value of attribute price.



4
5
6
# File 'lib/bitstamper/models/transaction.rb', line 4

def price
  @price
end

#transaction_typeObject

Returns the value of attribute transaction_type.



4
5
6
# File 'lib/bitstamper/models/transaction.rb', line 4

def transaction_type
  @transaction_type
end

#typeObject

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