Class: Trade
- Inherits:
-
Object
- Object
- Trade
- Defined in:
- lib/trades/trade.rb
Instance Attribute Summary collapse
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#market ⇒ Object
readonly
Returns the value of attribute market.
-
#price ⇒ Object
Returns the value of attribute price.
-
#timestamp(show_date = false) ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#volume ⇒ Object
readonly
Returns the value of attribute volume.
Instance Method Summary collapse
-
#initialize(data) ⇒ Trade
constructor
A new instance of Trade.
- #to_s ⇒ Object
Constructor Details
#initialize(data) ⇒ Trade
Returns a new instance of Trade.
12 13 14 15 16 17 18 19 20 |
# File 'lib/trades/trade.rb', line 12 def initialize(data) parsed = JSON.parse data.strip.tr("\x00", '') @id = parsed['id'] @market = parsed['symbol'] @timestamp = parsed['timestamp'] @currency = parsed['symbol'][-3, 3] @price = parsed['price'] @volume = parsed['volume'] end |
Instance Attribute Details
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
7 8 9 |
# File 'lib/trades/trade.rb', line 7 def currency @currency end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/trades/trade.rb', line 4 def id @id end |
#market ⇒ Object (readonly)
Returns the value of attribute market.
5 6 7 |
# File 'lib/trades/trade.rb', line 5 def market @market end |
#price ⇒ Object
Returns the value of attribute price.
10 11 12 |
# File 'lib/trades/trade.rb', line 10 def price @price end |
#timestamp(show_date = false) ⇒ Object (readonly)
Returns the value of attribute timestamp.
6 7 8 |
# File 'lib/trades/trade.rb', line 6 def @timestamp end |
#volume ⇒ Object (readonly)
Returns the value of attribute volume.
8 9 10 |
# File 'lib/trades/trade.rb', line 8 def volume @volume end |
Instance Method Details
#to_s ⇒ Object
27 28 29 30 |
# File 'lib/trades/trade.rb', line 27 def to_s "#{@market.ljust(15)} | #{()} | #{@currency.ljust(9)} | " + "#{@price.round(4).to_s.ljust(9)} | #{@volume.to_s}" end |