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.



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

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.



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

def body_element
  @body_element
end

Returns the value of attribute footer_element.



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

def footer_element
  @footer_element
end

#header_elementObject

Returns the value of attribute header_element.



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

def header_element
  @header_element
end

Instance Method Details

#add_to_body(segment) ⇒ Object



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

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


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

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

#add_to_header(segment) ⇒ Object



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

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

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

Yields:



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

def body(&block)
  yield(@body_element)
end

Yields:



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

def footer(&block)
  yield(@footer_element)
end

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

Yields:



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

def header(&block)
  yield(@header_element)
end

#to_jsonObject



52
53
54
55
56
57
# File 'lib/eancom/edifact/document.rb', line 52

def to_json
  hash = {}
  hash.merge! @header_element.to_json_hash
  hash.merge! @body_element.to_json_hash
  hash.to_json
end

#to_s(debug: false) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/eancom/edifact/document.rb', line 44

def to_s(debug: false)
  stream = ''
  stream << @header_element.to_s(debug: debug)
  stream << @body_element.to_s(debug: debug)
  stream << @footer_element.to_s(debug: debug)
  stream
end

#total_segmentsObject

Should header and footer segments be added to total_segments?



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