Class: Reportinator::Template

Inherits:
Base
  • Object
show all
Defined in:
lib/reportinator/report/template.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

config, #config, logger, #logger

Methods included from Helpers

#merge_hash, #merge_hash!, #symbolize_attributes

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



3
4
5
# File 'lib/reportinator/report/template.rb', line 3

def children
  @children
end

Class Method Details

.load(params = {}) ⇒ Object



9
10
11
12
# File 'lib/reportinator/report/template.rb', line 9

def self.load(params = {})
  template = new(params)
  template.register
end

Instance Method Details

#parse(meta = {}, data = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/reportinator/report/template.rb', line 19

def parse(meta = {}, data = {})
  output = []
  new_meta = 
  combine_meta = merge_hash(meta, new_meta)
  new_data = attributes.transform_keys { |key| key.to_sym }
  combine_data = merge_hash(new_data, data)
  if children.present? && children.respond_to?(:to_ary)
    children.each do |child|
      output += child.parse(combine_meta, combine_data) do |combine_data, meta, new_meta|
        yield(combine_data, meta, new_meta)
      end
    end
  else
    output << yield(combine_data, meta, new_meta)
  end
  output
end

#registerObject



14
15
16
17
# File 'lib/reportinator/report/template.rb', line 14

def register
  return load_template if template.present?
  self
end