Class: Tran

Inherits:
Object
  • Object
show all
Includes:
RowCalculator
Defined in:
lib/tran.rb,
lib/tran/version.rb

Constant Summary collapse

VERSION =
"0.0.2"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RowCalculator

#all_rows, #calculated_rows

Constructor Details

#initialize(xml, options) ⇒ Tran

Returns a new instance of Tran.



15
16
17
18
# File 'lib/tran.rb', line 15

def initialize(xml, options)
  @headers = options.fetch(:headers)
  @xml = xml
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



9
10
11
# File 'lib/tran.rb', line 9

def headers
  @headers
end

Class Method Details

.transform(xml, options) ⇒ Object



11
12
13
# File 'lib/tran.rb', line 11

def self.transform(xml, options)
  new(xml, options).transform
end

Instance Method Details

#documentObject



29
30
31
# File 'lib/tran.rb', line 29

def document
  @document ||= Ox.parse(@xml)
end

#transformObject



20
21
22
23
24
25
26
27
# File 'lib/tran.rb', line 20

def transform
  CSV.generate(headers: true) do |csv|
    csv << headers.values
    calculated_rows.each do |row|
      csv << row
    end
  end
end