lib/mcoin/data/ticker.rb in mcoin-0.2.0 vs lib/mcoin/data/ticker.rb in mcoin-0.2.1

- old
+ new

@@ -3,30 +3,40 @@ module Mcoin module Data # :nodoc: class Ticker attr_reader :market, :type, :currency - attr_accessor :last, :ask, :bid, :low, :high, :volume + attr_accessor :last, :ask, :bid, :low, :high, :volume, :timestamp def initialize(market, type, currency, data = {}) @market = market @type = type @currency = currency data.each do |key, value| send("#{key}=", value) end end - def to_influx(tags = {}, values = {}) - tags = { type: @type, currency: @currency, market: @market }.merge(tags) + def time + Time.at(timestamp.to_i).to_s + end + + def to_influx + tags = { type: @type, currency: @currency, market: @market } values = { last: @last, ask: @ask, bid: @bid, low: @low, high: @high, volume: @volume - }.merge(values) + } "prices,#{tags.map { |t| t.join('=') }.join(',')} " \ - "#{values.map { |v| v.join('=') }.join(',')}" + "#{values.map { |v| v.join('=') }.join(',')} #{influx_time}" + end + + private + + def influx_time + (timestamp.to_f * (10**9)).to_i.to_s end end end end