Class: Capwatch::Fund
- Inherits:
-
Object
- Object
- Capwatch::Fund
- Defined in:
- lib/capwatch/fund.rb
Instance Attribute Summary collapse
-
#coins ⇒ Object
Returns the value of attribute coins.
-
#config ⇒ Object
Returns the value of attribute config.
-
#positions ⇒ Object
Returns the value of attribute positions.
-
#provider ⇒ Object
Returns the value of attribute provider.
Instance Method Summary collapse
- #[](symbol) ⇒ Object
- #build ⇒ Object
- #calculator ⇒ Object
- #console_table ⇒ Object
- #fund_totals ⇒ Object
-
#initialize(provider:, config:) ⇒ Fund
constructor
A new instance of Fund.
- #percent_change_1h ⇒ Object
- #percent_change_24h ⇒ Object
- #percent_change_7d ⇒ Object
- #serialize ⇒ Object
- #value_btc ⇒ Object
- #value_eth ⇒ Object
- #value_usd ⇒ Object
Constructor Details
#initialize(provider:, config:) ⇒ Fund
7 8 9 10 11 12 13 |
# File 'lib/capwatch/fund.rb', line 7 def initialize(provider:, config:) @provider = provider @config = config @positions = config.positions @coins = config.coins build end |
Instance Attribute Details
#coins ⇒ Object
Returns the value of attribute coins.
5 6 7 |
# File 'lib/capwatch/fund.rb', line 5 def coins @coins end |
#config ⇒ Object
Returns the value of attribute config.
5 6 7 |
# File 'lib/capwatch/fund.rb', line 5 def config @config end |
#positions ⇒ Object
Returns the value of attribute positions.
5 6 7 |
# File 'lib/capwatch/fund.rb', line 5 def positions @positions end |
#provider ⇒ Object
Returns the value of attribute provider.
5 6 7 |
# File 'lib/capwatch/fund.rb', line 5 def provider @provider end |
Instance Method Details
#[](symbol) ⇒ Object
15 16 17 |
# File 'lib/capwatch/fund.rb', line 15 def [](symbol) coins.find { |coin| coin.symbol == symbol } end |
#build ⇒ Object
43 44 45 46 47 |
# File 'lib/capwatch/fund.rb', line 43 def build calculator.assign_quantity calculator.assign_prices calculator.distribution end |
#calculator ⇒ Object
49 50 51 |
# File 'lib/capwatch/fund.rb', line 49 def calculator @calculator ||= FundCalculator.new(self) end |
#console_table ⇒ Object
67 68 69 |
# File 'lib/capwatch/fund.rb', line 67 def console_table Console.new(name = config.name, body = serialize, totals = fund_totals).draw_table end |
#fund_totals ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/capwatch/fund.rb', line 57 def fund_totals { value_usd: value_usd, value_btc: value_btc, value_eth: value_eth, percent_change_24h: percent_change_24h, percent_change_7d: percent_change_7d } end |
#percent_change_1h ⇒ Object
31 32 33 |
# File 'lib/capwatch/fund.rb', line 31 def percent_change_1h coins.map { |coin| coin.percent_change_1h * coin.distribution }.sum end |
#percent_change_24h ⇒ Object
35 36 37 |
# File 'lib/capwatch/fund.rb', line 35 def percent_change_24h coins.map { |coin| coin.percent_change_24h * coin.distribution }.sum end |
#percent_change_7d ⇒ Object
39 40 41 |
# File 'lib/capwatch/fund.rb', line 39 def percent_change_7d coins.map { |coin| coin.percent_change_7d * coin.distribution }.sum end |
#serialize ⇒ Object
53 54 55 |
# File 'lib/capwatch/fund.rb', line 53 def serialize coins.map { |coin| coin.serialize }.to_json end |
#value_btc ⇒ Object
19 20 21 |
# File 'lib/capwatch/fund.rb', line 19 def value_btc coins.map(&:value_btc).sum end |
#value_eth ⇒ Object
27 28 29 |
# File 'lib/capwatch/fund.rb', line 27 def value_eth coins.map(&:value_eth).sum end |
#value_usd ⇒ Object
23 24 25 |
# File 'lib/capwatch/fund.rb', line 23 def value_usd coins.map(&:value_usd).sum end |