Class: EDI::Segment

Inherits:
Collection_S show all
Defined in:
lib/edi4r.rb,
lib/edi4r/rexml.rb

Direct Known Subclasses

E::Segment

Instance Attribute Summary collapse

Attributes inherited from Collection_S

#maxrep, #rep, #status

Attributes inherited from Object

#name, #parent, #root

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Collection_S

#each_BCDS, #empty?, #fmt_of_DE, #initialize, #required?, #to_xml, #validate

Methods inherited from Collection

#==, #each, #find_all, #first, #index, #initialize, #last, #length, #map, #names, #normalized_class_name, #root=, #size

Methods inherited from Object

#initialize

Constructor Details

This class inherits a constructor from EDI::Collection_S

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class EDI::Collection

Instance Attribute Details

#levelObject (readonly)

Returns the value of attribute level



648
649
650
# File 'lib/edi4r.rb', line 648

def level
  @level
end

#sg_nameObject (readonly)

Returns the value of attribute sg_name



648
649
650
# File 'lib/edi4r.rb', line 648

def sg_name
  @sg_name
end

Class Method Details

.parse_xml(p, xseg) ⇒ Object



217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/edi4r/rexml.rb', line 217

def Segment.parse_xml( p, xseg )
  tag = xseg.attributes['name']
  seg = p.new_segment(tag)
  xseg.elements.each('CDE') do |xcde|
    cde_name = xcde.attributes['name']
    i = (xcde.attributes['instance'] || 1).to_i - 1
    cde = seg[cde_name][i]
    Segment.parse_xml_de( cde, xcde )
  end
  Segment.parse_xml_de( seg, xseg )
  seg
end

Instance Method Details

#[](xpath_expr) ⇒ Object

Access by XPath expression (support is very limited currently) or by name of the dependent component. Pass them as strings.

Used internally - try to avoid at user level! Currently supported XPath expressions:

  • descendant::*

  • descendant-or-self::*

  • child::*

  • child-or-self::*



699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
# File 'lib/edi4r.rb', line 699

def []( xpath_expr )
  return super( xpath_expr ) if xpath_expr.is_a? Integer

  msg_unsupported = "Unsupported XPath expression: #{xpath_expr}"

  case xpath_expr

  when /\A(descendant|child)(-or-self)?::(.*)/
    return xpath_matches($1, $2, $3, msg_unsupported)

    # Currently no real path, no predicate available supported
  when /\//, /\[/, /\]/
    raise IndexError, msg_unsupported

  when /child::(\w+)/ # ignore & accept default axis "child"
    return super( $1 )

  when /::/ # No other axes supported for now
    raise IndexError, msg_unsupported

  else # assume simple element name
    return super( xpath_expr )
  end
end

#childrenObject

Returns all child elements of the current segment.



675
676
677
# File 'lib/edi4r.rb', line 675

def children
  self['child::*']
end

#children_and_selfObject

Returns the current segment and all of its child elements. Useful e.g. to deal with one instance of a segment group without traversing included segment groups.



683
684
685
# File 'lib/edi4r.rb', line 683

def children_and_self
  self['child-or-self::*']
end

#descendantsObject

Returns array of all segments that have the current segment as ancestor.



660
661
662
# File 'lib/edi4r.rb', line 660

def descendants
  self['descendant::*']
end

#descendants_and_selfObject

Returns array of all segments with the current segment as ancestor, including the current segment. For trigger segments, this method returns all segments of one instance of the corresponding segment group.



669
670
671
# File 'lib/edi4r.rb', line 669

def descendants_and_self
  self['descendant-or-self::*']
end

#inspect(indent = '', symlist = []) ⇒ Object



725
726
727
728
# File 'lib/edi4r.rb', line 725

def inspect( indent='', symlist=[] )
  symlist += [:sg_name, :level]
  super
end

#is_tnode?Boolean

Returns true if segment is a TNode (i.e. a trigger segment). Note that only TNodes may have descendants.

Returns:

  • (Boolean)


653
654
655
# File 'lib/edi4r.rb', line 653

def is_tnode?
  @tnode
end

#update_with(ni) ⇒ Object

Update attributes with information from a corresponding node instance



733
734
735
736
737
738
# File 'lib/edi4r.rb', line 733

def update_with( ni ) # :nodoc:
  return nil if ni.name != @name # Names must match; consider a raise!
  @status, @maxrep, @sg_name, @rep, @index, @level, @tnode = ni.status,\
  ni.maxrep, ni.sg_name, ni.inst_cnt, ni.index, ni.level, ni.is_tnode?
  self
end