Class: EdifactConverter::XML112EDI::EdiHandler

Inherits:
EmptyHandler
  • Object
show all
Defined in:
lib/edifact_converter/xml112edi/edi_handler.rb

Instance Attribute Summary collapse

Attributes inherited from EmptyHandler

#locator, #next_handler

Instance Method Summary collapse

Methods inherited from EmptyHandler

#method_missing

Constructor Details

#initialize(nexthandler = nil) ⇒ EdiHandler

Returns a new instance of EdiHandler.



22
23
24
25
# File 'lib/edifact_converter/xml112edi/edi_handler.rb', line 22

def initialize(nexthandler = nil)
  self.linebreak = "\n" if EdifactConverter::Configuration.format_edi
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class EdifactConverter::EmptyHandler

Instance Attribute Details

#binaryObject

Returns the value of attribute binary.



9
10
11
# File 'lib/edifact_converter/xml112edi/edi_handler.rb', line 9

def binary
  @binary
end

#edifactObject

Returns the value of attribute edifact.



9
10
11
# File 'lib/edifact_converter/xml112edi/edi_handler.rb', line 9

def edifact
  @edifact
end

#first_valueObject Also known as: first_value?

Returns the value of attribute first_value.



9
10
11
# File 'lib/edifact_converter/xml112edi/edi_handler.rb', line 9

def first_value
  @first_value
end

#linebreakObject

Returns the value of attribute linebreak.



9
10
11
# File 'lib/edifact_converter/xml112edi/edi_handler.rb', line 9

def linebreak
  @linebreak
end

#processing_binaryObject Also known as: processing_binary?

Returns the value of attribute processing_binary.



9
10
11
# File 'lib/edifact_converter/xml112edi/edi_handler.rb', line 9

def processing_binary
  @processing_binary
end

Instance Method Details

#binary?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/edifact_converter/xml112edi/edi_handler.rb', line 69

def binary?
  binary.any?
end

#endSegmentObject



61
62
63
64
65
66
67
# File 'lib/edifact_converter/xml112edi/edi_handler.rb', line 61

def endSegment
  if processing_binary?
    self.processing_binary = false
  else
    edifact.write("'#{linebreak}")
  end
end

#startDocumentObject



27
28
29
30
31
# File 'lib/edifact_converter/xml112edi/edi_handler.rb', line 27

def startDocument
  self.edifact = nil
  binary.clear
  edifact.write("UNA:+.? '#{linebreak}")
end

#startElementObject



41
42
43
44
45
46
# File 'lib/edifact_converter/xml112edi/edi_handler.rb', line 41

def startElement
  unless processing_binary?
    edifact.write('+')
    self.first_value = true
  end
end

#startSegment(name, position = nil) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/edifact_converter/xml112edi/edi_handler.rb', line 33

def startSegment(name, position = nil)
  if name == "OBJ"
    self.processing_binary = true
  else
    edifact.write(name)
  end
end

#value(text) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/edifact_converter/xml112edi/edi_handler.rb', line 48

def value(text)
  if processing_binary?
    id = binary_id
    binary[id] = text
    text = id
  elsif first_value
    self.first_value = false
  else
    edifact.write(':') unless first_value?
  end
  edifact.write text.to_s.gsub(/([\?:\'\+])/,'?\1')
end