Class: YahooStock::Base
- Inherits:
-
Object
- Object
- YahooStock::Base
- Defined in:
- lib/yahoo_stock/base.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#data_attributes ⇒ Object
Abstract method.
-
#find ⇒ Object
Uses the values method of the interface used to show results .
-
#initialize(interface) ⇒ Base
constructor
A new instance of Base.
-
#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.
- #symbols ⇒ Object
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_attributes ⇒ Object
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 |
#find ⇒ Object
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 |
#symbols ⇒ Object
15 16 17 |
# File 'lib/yahoo_stock/base.rb', line 15 def symbols @interface.stock_symbols end |