Class: Capwatch::Coin

Inherits:
Object
  • Object
show all
Defined in:
lib/capwatch/coin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Coin

Returns a new instance of Coin.

Yields:

  • (_self)

Yield Parameters:



12
13
14
# File 'lib/capwatch/coin.rb', line 12

def initialize
  yield self if block_given?
end

Instance Attribute Details

#distributionObject

Returns the value of attribute distribution.



5
6
7
# File 'lib/capwatch/coin.rb', line 5

def distribution
  @distribution
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/capwatch/coin.rb', line 5

def name
  @name
end

#percent_change_1hObject

Returns the value of attribute percent_change_1h.



5
6
7
# File 'lib/capwatch/coin.rb', line 5

def percent_change_1h
  @percent_change_1h
end

#percent_change_24hObject

Returns the value of attribute percent_change_24h.



5
6
7
# File 'lib/capwatch/coin.rb', line 5

def percent_change_24h
  @percent_change_24h
end

#percent_change_7dObject

Returns the value of attribute percent_change_7d.



5
6
7
# File 'lib/capwatch/coin.rb', line 5

def percent_change_7d
  @percent_change_7d
end

#price_btcObject

Returns the value of attribute price_btc.



5
6
7
# File 'lib/capwatch/coin.rb', line 5

def price_btc
  @price_btc
end

#price_usdObject

Returns the value of attribute price_usd.



5
6
7
# File 'lib/capwatch/coin.rb', line 5

def price_usd
  @price_usd
end

#quantityObject

Returns the value of attribute quantity.



5
6
7
# File 'lib/capwatch/coin.rb', line 5

def quantity
  @quantity
end

#symbolObject

Returns the value of attribute symbol.



5
6
7
# File 'lib/capwatch/coin.rb', line 5

def symbol
  @symbol
end

Instance Method Details

#price_ethObject



28
29
30
# File 'lib/capwatch/coin.rb', line 28

def price_eth
  price_btc / Exchange.rate_for("ETH")
end

#serializeObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/capwatch/coin.rb', line 32

def serialize
  {
    symbol: symbol,
    name: name,
    quantity: quantity,
    price_usd: price_usd,
    price_btc: price_btc,
    distribution: distribution,
    percent_change_1h: percent_change_1h,
    percent_change_24h: percent_change_24h,
    percent_change_7d: percent_change_7d,
    value_btc: value_btc,
    value_usd: value_usd,
    value_eth: value_eth,
    price_eth: price_eth,
  }
end

#value_btcObject



16
17
18
# File 'lib/capwatch/coin.rb', line 16

def value_btc
  price_btc * quantity
end

#value_ethObject



24
25
26
# File 'lib/capwatch/coin.rb', line 24

def value_eth
  price_eth * quantity
end

#value_usdObject



20
21
22
# File 'lib/capwatch/coin.rb', line 20

def value_usd
  price_usd * quantity
end