Class: StockMarkets::FileDataProcessor
- Inherits:
-
Object
- Object
- StockMarkets::FileDataProcessor
- Defined in:
- lib/stock_markets/file_data_processor.rb
Constant Summary collapse
- LAST_UPDATE_MARKET_MINIMAL_YEARS_COUNT =
2
- ACTIVE_MARKET_STATUS_NAME =
'ACTIVE'
- MARKET_NAME_CSV_COLUMN =
:nameinstitution_description
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
-
#initialize ⇒ FileDataProcessor
constructor
A new instance of FileDataProcessor.
- #load_data_for_mics! ⇒ Object
- #load_data_for_names! ⇒ Object
- #load_from_disk! ⇒ Object
- #transform_to_hash(key_name: :mic) ⇒ Object
Constructor Details
#initialize ⇒ FileDataProcessor
Returns a new instance of FileDataProcessor.
12 13 14 15 |
# File 'lib/stock_markets/file_data_processor.rb', line 12 def initialize @data = [] load_from_disk! end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
10 11 12 |
# File 'lib/stock_markets/file_data_processor.rb', line 10 def data @data end |
Instance Method Details
#load_data_for_mics! ⇒ Object
32 33 34 |
# File 'lib/stock_markets/file_data_processor.rb', line 32 def load_data_for_mics! transform_to_hash.data end |
#load_data_for_names! ⇒ Object
36 37 38 |
# File 'lib/stock_markets/file_data_processor.rb', line 36 def load_data_for_names! transform_to_hash(key_name: MARKET_NAME_CSV_COLUMN).data end |
#load_from_disk! ⇒ Object
17 18 19 |
# File 'lib/stock_markets/file_data_processor.rb', line 17 def load_from_disk! self.parsed_csv = CSV.table(StockMarkets.configuration.data_file_path) end |
#transform_to_hash(key_name: :mic) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/stock_markets/file_data_processor.rb', line 21 def transform_to_hash(key_name: :mic) raise TypeError, 'Invalid object of CSV provided!' unless parsed_csv.instance_of?(CSV::Table) self.data = parsed_csv.each_with_object({}) do |data_row, result_hash| if market_recently_updated_proc.call(data_row, key_name) result_hash[data_row[key_name.to_sym]] = data_row.to_h end end self end |