Class: Eancom::Edifact::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/eancom/edifact/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocument

Returns a new instance of Document.



8
9
10
11
12
# File 'lib/eancom/edifact/document.rb', line 8

def initialize
  @header_element = Header.new
  @body_element = Body.new
  @footer_element = Footer.new
end

Instance Attribute Details

#body_elementObject

Returns the value of attribute body_element.



6
7
8
# File 'lib/eancom/edifact/document.rb', line 6

def body_element
  @body_element
end

Returns the value of attribute footer_element.



6
7
8
# File 'lib/eancom/edifact/document.rb', line 6

def footer_element
  @footer_element
end

#header_elementObject

Returns the value of attribute header_element.



6
7
8
# File 'lib/eancom/edifact/document.rb', line 6

def header_element
  @header_element
end

Instance Method Details

#add_to_body(segment) ⇒ Object



30
31
32
# File 'lib/eancom/edifact/document.rb', line 30

def add_to_body(segment)
  @body_element.segment(segment)
end


34
35
36
# File 'lib/eancom/edifact/document.rb', line 34

def add_to_footer(segment)
  @footer_element.segment(segment)
end

#add_to_header(segment) ⇒ Object



26
27
28
# File 'lib/eancom/edifact/document.rb', line 26

def add_to_header(segment)
  @header_element.segment(segment)
end

#body {|@body_element| ... } ⇒ Object

Yields:



18
19
20
# File 'lib/eancom/edifact/document.rb', line 18

def body
  yield(@body_element)
end

Yields:



22
23
24
# File 'lib/eancom/edifact/document.rb', line 22

def footer
  yield(@footer_element)
end

#header {|@header_element| ... } ⇒ Object

Yields:



14
15
16
# File 'lib/eancom/edifact/document.rb', line 14

def header
  yield(@header_element)
end

#to_json(_obj = nil) ⇒ Object



48
49
50
51
52
53
# File 'lib/eancom/edifact/document.rb', line 48

def to_json(_obj = nil)
  {
    **@header_element.to_json_hash,
    **@body_element.to_json_hash
  }.to_json
end

#to_s(debug: false) ⇒ Object



44
45
46
# File 'lib/eancom/edifact/document.rb', line 44

def to_s(debug: false)
  "#{@header_element.to_s(debug: debug)}#{@body_element.to_s(debug: debug)}#{@footer_element.to_s(debug: debug)}"
end

#total_segmentsObject



38
39
40
41
42
# File 'lib/eancom/edifact/document.rb', line 38

def total_segments
  total = 0
  total += @body_element.segments.count
  total
end