Class: StockMarkit::Chart
- Inherits:
-
Object
- Object
- StockMarkit::Chart
- Includes:
- HTTParty
- Defined in:
- lib/stock-markit/chart.rb
Overview
Stock Chart Object
- Copyright
-
Copyright © 2016 Michael Heijmans
- License
-
MIT
Instance Attribute Summary collapse
-
#results ⇒ StockMarkit::ChartResult
readonly
The chart results.
Instance Method Summary collapse
-
#data_interval ⇒ Integer
Value of passed data_interval parameter on instantiation.
-
#data_period ⇒ Symbol
Value of passed data_period parameter on instantiation.
-
#elements ⇒ Array
List of normalized elements passed on instantiation.
-
#end_date ⇒ String
Value of passed end_time parameter in ISO8601 formatted Eastern Time.
-
#fetch ⇒ StockMarkit::ChartResults
loads the @results on first call or returns results on subsequent calls.
-
#initialize(opts) ⇒ Chart
constructor
A new instance of Chart.
-
#label_interval ⇒ Integer
Value of passed label_interval parameter on instantiation.
-
#label_period ⇒ Symbol
Value of passed label_period parameter on instantiation.
-
#normalized? ⇒ Boolean
Value of the passed normalized parameter on instantiation.
-
#number_of_days ⇒ Integer
Value of passed number_of_days parameter on instantiation.
-
#offset ⇒ Integer
Value of passed offset parameter on instantiation.
-
#start_date ⇒ String
Value of passed start_time parameter in ISO8601 formatted Eastern Time.
-
#update ⇒ StockMarkit::ChartResult
updates the data from the api.
Constructor Details
#initialize(opts) ⇒ Chart
Returns a new instance of Chart.
32 33 34 |
# File 'lib/stock-markit/chart.rb', line 32 def initialize(opts) @opts = opts end |
Instance Attribute Details
#results ⇒ StockMarkit::ChartResult (readonly)
The chart results
16 17 18 |
# File 'lib/stock-markit/chart.rb', line 16 def results @results end |
Instance Method Details
#data_interval ⇒ Integer
Returns value of passed data_interval parameter on instantiation.
69 70 71 |
# File 'lib/stock-markit/chart.rb', line 69 def data_interval @opts[:data_interval] end |
#data_period ⇒ Symbol
Returns value of passed data_period parameter on instantiation.
63 64 65 66 |
# File 'lib/stock-markit/chart.rb', line 63 def data_period raise "valid data_periods are #{allowed_periods.join(", ")}" unless allowed_periods.include? @opts[:data_period] @opts[:data_period].to_s.capitalize end |
#elements ⇒ Array
Returns List of normalized elements passed on instantiation.
86 87 88 |
# File 'lib/stock-markit/chart.rb', line 86 def elements @opts[:elements].map{ |element| {"Symbol" => element.symbol, "Type" => element.type, "Params" => [element.params]} } end |
#end_date ⇒ String
Returns value of passed end_time parameter in ISO8601 formatted Eastern Time.
48 49 50 |
# File 'lib/stock-markit/chart.rb', line 48 def end_date format_time(@opts[:end_date]) end |
#fetch ⇒ StockMarkit::ChartResults
loads the @results on first call or returns results on subsequent calls
93 94 95 |
# File 'lib/stock-markit/chart.rb', line 93 def fetch @results || update end |
#label_interval ⇒ Integer
Returns value of passed label_interval parameter on instantiation.
81 82 83 |
# File 'lib/stock-markit/chart.rb', line 81 def label_interval @opts[:label_interval] end |
#label_period ⇒ Symbol
Returns value of passed label_period parameter on instantiation.
74 75 76 77 78 |
# File 'lib/stock-markit/chart.rb', line 74 def label_period return nil unless @opts[:label_period] raise "valid label_periods are #{allowed_periods.join(", ")}" unless allowed_periods.include? @opts[:label_period] @opts[:label_period].to_s.capitalize end |
#normalized? ⇒ Boolean
Returns value of the passed normalized parameter on instantiation.
37 38 39 40 |
# File 'lib/stock-markit/chart.rb', line 37 def normalized? return true if @opts[:normalized].nil? @opts[:normalized] end |
#number_of_days ⇒ Integer
Returns value of passed number_of_days parameter on instantiation.
58 59 60 |
# File 'lib/stock-markit/chart.rb', line 58 def number_of_days @opts[:number_of_days] end |
#offset ⇒ Integer
Returns value of passed offset parameter on instantiation.
53 54 55 |
# File 'lib/stock-markit/chart.rb', line 53 def offset @opts[:offset] end |
#start_date ⇒ String
Returns value of passed start_time parameter in ISO8601 formatted Eastern Time.
43 44 45 |
# File 'lib/stock-markit/chart.rb', line 43 def start_date format_time(@opts[:start_date]) end |
#update ⇒ StockMarkit::ChartResult
updates the data from the api
100 101 102 |
# File 'lib/stock-markit/chart.rb', line 100 def update @results = lookup_with_api end |