Class: Stockboy::Provider Abstract
- Inherits:
-
Object
- Object
- Stockboy::Provider
- Extended by:
- DSL
- Defined in:
- lib/stockboy/provider.rb
Overview
Provider objects handle the connection and capture of data from remote sources. This is an abstract superclass to help implement different providers.
Interface
A provider object must implement the following (private) methods:
- validate
-
Verify the parameters required for the data source are set to ensure a connection can be established.
- fetch_data
-
Populate the object’s @data with raw content from source. This will usually be a raw string, and should not be parsed at this stage. Depending on the implementation, this may involve any of:
-
Establishing a connection
-
Navigating to a directory
-
Listing available files matching the configuration
-
Picking the appropriate file
-
And finally, reading/downloading data
This should also capture the timestamp of the data resource into @data_time. This should be the actual created or updated time of the data file from the source.
-
Direct Known Subclasses
Stockboy::Providers::FTP, Stockboy::Providers::File, Stockboy::Providers::HTTP, Stockboy::Providers::IMAP, Stockboy::Providers::SOAP
Instance Attribute Summary collapse
-
#data {|@data| ... } ⇒ Object
readonly
Raw input data from the source.
-
#data_size ⇒ Time
readonly
Size of the received data.
-
#data_time ⇒ Time
readonly
Timestamp of the received data.
- #errors ⇒ Array readonly
- #logger ⇒ Logger
Instance Method Summary collapse
-
#clear ⇒ Boolean
(also: #reset)
Reset received data.
-
#data?(_ = nil) ⇒ Boolean
Determine if there is returned data.
-
#initialize(opts = {}) { ... } ⇒ Provider
constructor
Must be called by subclasses via
super
to set up dependencies. - #inspect ⇒ String
-
#reload ⇒ String
Reload provided data.
-
#valid? ⇒ Boolean
Does the provider have what it needs for fetching data?.
Constructor Details
Instance Attribute Details
#data {|@data| ... } ⇒ Object (readonly)
Raw input data from the source
78 79 80 81 82 |
# File 'lib/stockboy/provider.rb', line 78 def data fetch_data if @data.nil? && validate_config? yield @data if block_given? @data end |
#data_size ⇒ Time (readonly)
Size of the received data
48 49 50 |
# File 'lib/stockboy/provider.rb', line 48 def data_size @data_size end |
#data_time ⇒ Time (readonly)
Timestamp of the received data
54 55 56 |
# File 'lib/stockboy/provider.rb', line 54 def data_time @data_time end |
#errors ⇒ Array (readonly)
42 43 44 |
# File 'lib/stockboy/provider.rb', line 42 def errors @errors end |
#logger ⇒ Logger
38 39 40 |
# File 'lib/stockboy/provider.rb', line 38 def logger @logger end |
Instance Method Details
#clear ⇒ Boolean Also known as: reset
Reset received data
95 96 97 98 99 100 101 |
# File 'lib/stockboy/provider.rb', line 95 def clear @data = nil @data_time = nil @data_size = nil @errors = [] true end |
#data?(_ = nil) ⇒ Boolean
Determine if there is returned data
86 87 88 89 |
# File 'lib/stockboy/provider.rb', line 86 def data?(_=nil) return nil unless @data @data && !@data.empty? end |
#inspect ⇒ String
58 59 60 61 62 |
# File 'lib/stockboy/provider.rb', line 58 def inspect "#<#{self.class}:#{self.object_id} "\ "data_size=#{@data_size.inspect} "\ "errors=[#{errors.join(", ")}]>" end |
#reload ⇒ String
Reload provided data
108 109 110 111 112 |
# File 'lib/stockboy/provider.rb', line 108 def reload clear fetch_data if validate_config? @data end |
#valid? ⇒ Boolean
Does the provider have what it needs for fetching data?
118 119 120 |
# File 'lib/stockboy/provider.rb', line 118 def valid? validate end |