Class: EdifactConverter::AbstractSyntaxTree
- Inherits:
-
Object
- Object
- EdifactConverter::AbstractSyntaxTree
- Defined in:
- lib/edifact_converter/abstract_syntax_tree.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
Instance Method Summary collapse
- #compare(document, &proc) ⇒ Object
-
#initialize(document) ⇒ AbstractSyntaxTree
constructor
A new instance of AbstractSyntaxTree.
- #pack ⇒ Object
- #set_checksums ⇒ Object
- #verify_segments_checksum(&proc) ⇒ Object
Constructor Details
#initialize(document) ⇒ AbstractSyntaxTree
Returns a new instance of AbstractSyntaxTree.
9 10 11 12 |
# File 'lib/edifact_converter/abstract_syntax_tree.rb', line 9 def initialize(document) self.document = document raise 'hell' unless document end |
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
7 8 9 |
# File 'lib/edifact_converter/abstract_syntax_tree.rb', line 7 def document @document end |
Instance Method Details
#compare(document, &proc) ⇒ Object
18 19 20 |
# File 'lib/edifact_converter/abstract_syntax_tree.rb', line 18 def compare(document, &proc) Comparator.new.compare_docs(self.document, document, &proc) end |
#pack ⇒ Object
14 15 16 |
# File 'lib/edifact_converter/abstract_syntax_tree.rb', line 14 def pack pack_root(document.root) if document.root end |
#set_checksums ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/edifact_converter/abstract_syntax_tree.rb', line 41 def set_checksums document.xpath("//Brev").each do |brev| sum = count_segments(brev) brev.xpath("UNT/Elm[1]/SubElm").each do |elm| elm.content = sum end end end |
#verify_segments_checksum(&proc) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/edifact_converter/abstract_syntax_tree.rb', line 22 def verify_segments_checksum(&proc) errors = [] proc ||= Proc.new { |n| errors << n } document.xpath("//Brev").each do |brev| sum = count_segments brev unt = brev.at("UNT/Elm[1]/SubElm/text()") || '0' if sum != unt.to_s.to_i proc.call( Difference.new( source: brev.at("UNT"), facit: sum, kind: :unt ) ) end end errors end |