Class: Yfin::History

Inherits:
Object
  • Object
show all
Defined in:
lib/yfin/history.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol, options = {}) ⇒ History

Returns a new instance of History.



5
6
7
8
9
10
11
# File 'lib/yfin/history.rb', line 5

def initialize(symbol, options={})
  validate_options(options)
  @symbol     = symbol
  @start_date = options[:start_date] || Date.today - 30
  @end_date   = options[:end_date] || Date.today
  @type       = options[:type] || :daily
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



3
4
5
# File 'lib/yfin/history.rb', line 3

def end_date
  @end_date
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



3
4
5
# File 'lib/yfin/history.rb', line 3

def start_date
  @start_date
end

#symbolObject (readonly)

Returns the value of attribute symbol.



3
4
5
# File 'lib/yfin/history.rb', line 3

def symbol
  @symbol
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/yfin/history.rb', line 3

def type
  @type
end

Instance Method Details

#to_csvObject



13
14
15
# File 'lib/yfin/history.rb', line 13

def to_csv
  CSV.parse(data_from_yahoo, headers: :first_line, header_converters: :symbol, converters: [:date, :numeric])
end