Class: NBP::XMLFilesList

Inherits:
Object
  • Object
show all
Includes:
Commons
Defined in:
lib/nbp/xml_files_list.rb

Constant Summary collapse

BASE_NAME =
'dir'

Constants included from Commons

Commons::CORE_WEB_PATH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Commons

extended, #nbp_date_format_hash

Constructor Details

#initialize(date, file_extension = '.txt') ⇒ XMLFilesList

Returns a new instance of XMLFilesList.



12
13
14
15
16
# File 'lib/nbp/xml_files_list.rb', line 12

def initialize(date, file_extension = '.txt')
  @dir_name = files_list_name(date) + file_extension
  @formatted_date = nbp_date_format_string(date)
  @matched_base_file_names = []
end

Instance Attribute Details

#dir_nameObject (readonly)

Returns the value of attribute dir_name.



6
7
8
# File 'lib/nbp/xml_files_list.rb', line 6

def dir_name
  @dir_name
end

#matched_base_file_namesObject (readonly)

Returns the value of attribute matched_base_file_names.



6
7
8
# File 'lib/nbp/xml_files_list.rb', line 6

def matched_base_file_names
  @matched_base_file_names
end

Instance Method Details

#fetch_file_namesObject



18
19
20
21
22
23
24
# File 'lib/nbp/xml_files_list.rb', line 18

def fetch_file_names
  dir_file = open(Commons::CORE_WEB_PATH + dir_name, 'r')
  @matched_base_file_names = dir_file.each_line.with_object([]) do |line, arr|
    trim_line = line.strip
    arr << trim_line if trim_line[-6..-1] == formatted_date
  end
end

#matched_file_names_as_hashesObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/nbp/xml_files_list.rb', line 26

def matched_file_names_as_hashes
  matched_base_file_names.map do |name|
    { table_name: name[0],
      table_number: name[1..3],
      constant_element: name[4],
      year: name[5..6],
      month: name[7..8],
      day: name[9..10],
      extension: name[-4..-1] }
  end
end