Class: StockMarkets::FileDataProcessor

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeFileDataProcessor

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

#dataObject

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

Raises:

  • (TypeError)


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