Class: GlobalCollect::LogParsing::CollectionReport::AppendixReportFile

Inherits:
Object
  • Object
show all
Defined in:
lib/global_collect/log_parsing/collection_report/appendix_report_file.rb

Constant Summary collapse

FILENAME_FORMAT =

RG - Ch9 => Technical aspects => File name 4 chars numeric account id, 8 chars date in YYYMMDD

/^(\d{4})(\d{8})\.csv$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ AppendixReportFile

Returns a new instance of AppendixReportFile.



8
9
10
11
12
13
14
15
16
17
# File 'lib/global_collect/log_parsing/collection_report/appendix_report_file.rb', line 8

def initialize(path)
  @path = path
  if File.basename(path) =~ FILENAME_FORMAT
    @account_id = $1
    @date = Date.strptime($2, "%Y%m%d")
    @environment = :production
  else
    raise ArgumentError.new("Unparseable path '#{path}'!")
  end
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



3
4
5
# File 'lib/global_collect/log_parsing/collection_report/appendix_report_file.rb', line 3

def 
  @account_id
end

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/global_collect/log_parsing/collection_report/appendix_report_file.rb', line 3

def data
  @data
end

#dateObject (readonly)

Returns the value of attribute date.



3
4
5
# File 'lib/global_collect/log_parsing/collection_report/appendix_report_file.rb', line 3

def date
  @date
end

#environmentObject (readonly)

Returns the value of attribute environment.



3
4
5
# File 'lib/global_collect/log_parsing/collection_report/appendix_report_file.rb', line 3

def environment
  @environment
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/global_collect/log_parsing/collection_report/appendix_report_file.rb', line 3

def path
  @path
end

Instance Method Details

#parseObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/global_collect/log_parsing/collection_report/appendix_report_file.rb', line 19

def parse
  begin
    file = File.open(@path, "r")
    csv = FasterCSV.new(file,
      :col_sep => ";",
      :headers => FIELDS.map(&:first)
    )
    @data = {:data_records => csv.map{|l| convert_line(l) }}
  ensure
    file.close
  end
end