class Psei::Formatter

Formats the parsed data

Public Class Methods

new() click to toggle source
# File lib/psei/formatter.rb, line 4
def initialize
  @arr = []
end

Public Instance Methods

process(arr) click to toggle source
# File lib/psei/formatter.rb, line 8
def process arr
  @arr = arr
  @arr ? to_hash : {}
end

Private Instance Methods

float_format(val) click to toggle source
# File lib/psei/formatter.rb, line 19
def float_format val
  val.to_s.gsub(',','').to_f
end
get_last_price() click to toggle source
# File lib/psei/formatter.rb, line 31
def get_last_price
  float_format @arr['lastTradedPrice']
end
get_percent_change() click to toggle source
# File lib/psei/formatter.rb, line 27
def get_percent_change
  float_format @arr['percChangeClose']
end
get_total_volume() click to toggle source
# File lib/psei/formatter.rb, line 23
def get_total_volume
  float_format @arr['totalVolume']
end
int_format(val) click to toggle source
# File lib/psei/formatter.rb, line 15
def int_format val
  val.to_s.gsub(',', '').to_i
end
to_hash() click to toggle source
# File lib/psei/formatter.rb, line 39
def to_hash
  { 
    symbol: @arr['securitySymbol'],
    alias: @arr['securityAlias'],
    total_volume: get_total_volume,
    updown: up_or_down,
    percent_change: get_percent_change,
    last_price: get_last_price
  }
end
up_or_down() click to toggle source
# File lib/psei/formatter.rb, line 35
def up_or_down
  @arr['indicator'] == "U" ? 'up' : 'down'
end