Sha256: c39eaa367f349a86963e7a815c0582d93e77b38b4938d3a498f1fe5b4da1f70e

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Capwatch
  class Coin
    attr_accessor :name, :symbol, :quantity,
                  :price_usd, :price_btc,
                  :distribution,
                  :percent_change_1h,
                  :percent_change_24h,
                  :percent_change_7d

    def initialize
      yield self if block_given?
    end

    def value_btc
      price_btc * quantity
    end

    def value_usd
      price_usd * quantity
    end

    def value_eth
      price_eth * quantity
    end

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

    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

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
capwatch-0.2.5 lib/capwatch/coin.rb
capwatch-0.2.4 lib/capwatch/coin.rb
capwatch-0.2.3 lib/capwatch/coin.rb
capwatch-0.2.0 lib/capwatch/coin.rb