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


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

def initialize(interface)
  @interface = interface
end

Instance Method Details

#data_attributesObject

Abstract method


31
32
33
# File 'lib/yahoo_stock/base.rb', line 31

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


20
21
22
23
24
25
26
27
28
# File 'lib/yahoo_stock/base.rb', line 20

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}
  end
end