Class: FTF::Mappings::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/ftf/mappings/report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Report

Returns a new instance of Report.



8
9
10
11
# File 'lib/ftf/mappings/report.rb', line 8

def initialize(data)
  @data = parse(data)
  @products = @data[:products].map { |product| Product.new(product, self) }
end

Instance Attribute Details

#productsObject (readonly)

Returns the value of attribute products.



6
7
8
# File 'lib/ftf/mappings/report.rb', line 6

def products
  @products
end

Instance Method Details

#file_typeObject



40
41
42
# File 'lib/ftf/mappings/report.rb', line 40

def file_type
  @data[:file_type]
end

#fiscal_idObject



32
33
34
# File 'lib/ftf/mappings/report.rb', line 32

def fiscal_id
  @data[:fiscal_id]
end

#indexObject



48
49
50
51
# File 'lib/ftf/mappings/report.rb', line 48

def index
  index = @data[:index] || 1
  index.to_s.rjust(3, "0")
end

#parse(data) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/ftf/mappings/report.rb', line 13

def parse(data)
  case data
  when Hash
    data
  when String
    JSON.parse(data, symbolize_names: true)
  else
    raise "Please provide a JSON string to parse or a symbol-keyed hash"
  end
end

#periodObject



36
37
38
# File 'lib/ftf/mappings/report.rb', line 36

def period
  @data[:period]
end


28
29
30
# File 'lib/ftf/mappings/report.rb', line 28

def render_footer(index)
  Records::Footer.new(index, self).render
end

#render_header(index) ⇒ Object



24
25
26
# File 'lib/ftf/mappings/report.rb', line 24

def render_header(index)
  Records::Header.new(index, self).render
end

#request_idObject



44
45
46
# File 'lib/ftf/mappings/report.rb', line 44

def request_id
  @data[:request_id]
end