Class: Hippo::TransactionSets::RepeatingComponent

Inherits:
Array
  • Object
show all
Includes:
Outputters::HTML::RepeatingComponent, Outputters::PDF::RepeatingComponent, Outputters::PrettyString::RepeatingComponent
Defined in:
lib/hippo/transaction_sets/repeating_component.rb

Instance Method Summary collapse

Methods included from Outputters::PrettyString::RepeatingComponent

#pretty_print, #to_pretty_string

Methods included from Outputters::PDF::RepeatingComponent

#to_pdf

Methods included from Outputters::HTML::RepeatingComponent

#to_html

Constructor Details

#initialize(component_entry, parent) ⇒ RepeatingComponent

Returns a new instance of RepeatingComponent.



7
8
9
10
# File 'lib/hippo/transaction_sets/repeating_component.rb', line 7

def initialize(component_entry, parent)
  @component_entry = component_entry
  @parent = parent
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



42
43
44
45
46
# File 'lib/hippo/transaction_sets/repeating_component.rb', line 42

def method_missing(method_name, *args, &block)
  build if self.length == 0

  self.first.send(method_name, *args, &block)
end

Instance Method Details

#ancestorsObject



34
35
36
37
38
39
40
# File 'lib/hippo/transaction_sets/repeating_component.rb', line 34

def ancestors
  if parent
    parent.ancestors.flatten
  else
    []
  end
end

#build {|component| ... } ⇒ Object

Yields:

  • (component)


12
13
14
15
16
17
18
# File 'lib/hippo/transaction_sets/repeating_component.rb', line 12

def build
  component = @component_entry.populate_component(@component_entry.klass.new(:parent => @parent))

  push(component)
  yield component if block_given?
  component
end

#segment_countObject



30
31
32
# File 'lib/hippo/transaction_sets/repeating_component.rb', line 30

def segment_count
  segments.length
end

#segmentsObject



24
25
26
27
28
# File 'lib/hippo/transaction_sets/repeating_component.rb', line 24

def segments
  return [] unless self.length != 0

  self.map(&:segments).flatten
end

#to_sObject



20
21
22
# File 'lib/hippo/transaction_sets/repeating_component.rb', line 20

def to_s
  self.map(&:to_s).join
end