Class: YahooStock::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/yahoo_stock/base.rb

Direct Known Subclasses

History, Quote, ScripSymbol

Instance Method Summary collapse

Constructor Details

#initialize(interface) ⇒ Base

Returns a new instance of Base.



6
7
8
# File 'lib/yahoo_stock/base.rb', line 6

def initialize(interface)
  @interface = interface
end

Instance Method Details

#data_attributesObject

Abstract method



36
37
38
# File 'lib/yahoo_stock/base.rb', line 36

def data_attributes
  raise 'Abstract method called. Use the subclass data_attributes method'
end

#findObject

Uses the values method of the interface used to show results .



11
12
13
# File 'lib/yahoo_stock/base.rb', line 11

def find
  @interface.values
end

#results(type = nil, &block) ⇒ Object

Method takes one parameter type or a block type uses the existing format classes namespaced in Result::ClassName.output e.g. * results :to_array

* results {YourSpecialFormat.method_name}

to store



24
25
26
27
28
29
30
31
32
33
# File 'lib/yahoo_stock/base.rb', line 24

def results(type=nil, &block)
  if block_given?
    yield
  else
    return YahooStock::Result.new(find) if !type || type.to_s.empty?
    format_type = type.to_s.sub(/^to_/,'').strip
    return YahooStock::Result.const_get("#{format_type.capitalize}Format").new(find){data_attributes} unless format_type == "hash"
    return YahooStock::Result.const_get("#{format_type.capitalize}Format").new(find, symbols){data_attributes}
  end
end

#symbolsObject



15
16
17
# File 'lib/yahoo_stock/base.rb', line 15

def symbols
  @interface.stock_symbols
end