Class: Edifunct::SegmentGroup
- Inherits:
-
Object
- Object
- Edifunct::SegmentGroup
- Defined in:
- lib/edifunct/segment_group.rb
Overview
Represents the logical grouping of segments.
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #add_segment(segment) ⇒ Object
- #create_group(segment_group_tag) ⇒ Object
-
#initialize(tag) ⇒ SegmentGroup
constructor
A new instance of SegmentGroup.
- #lookup_group(segment_group_tag) ⇒ Object
- #lookup_groups(segment_group_tag) ⇒ Object
- #lookup_segment(segment_tag, &block) ⇒ Object
- #lookup_segments(segment_tag) ⇒ Object
- #print_with_structure ⇒ Object
Constructor Details
#initialize(tag) ⇒ SegmentGroup
Returns a new instance of SegmentGroup.
11 12 13 14 15 16 17 |
# File 'lib/edifunct/segment_group.rb', line 11 def initialize(tag) @tag = tag @children = [] @child_segment_map = Hash.new { |hash, key| hash[key] = [] } @child_segment_group_map = Hash.new { |hash, key| hash[key] = [] } end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
9 10 11 |
# File 'lib/edifunct/segment_group.rb', line 9 def children @children end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
8 9 10 |
# File 'lib/edifunct/segment_group.rb', line 8 def tag @tag end |
Instance Method Details
#add_segment(segment) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/edifunct/segment_group.rb', line 19 def add_segment(segment) @children << segment @child_segment_map[segment.tag] << segment segment end |
#create_group(segment_group_tag) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/edifunct/segment_group.rb', line 26 def create_group(segment_group_tag) segment_group = SegmentGroup.new(segment_group_tag) @children << segment_group @child_segment_group_map[segment_group.tag] << segment_group segment_group end |
#lookup_group(segment_group_tag) ⇒ Object
39 40 41 |
# File 'lib/edifunct/segment_group.rb', line 39 def lookup_group(segment_group_tag) lookup_groups(segment_group_tag).first end |
#lookup_groups(segment_group_tag) ⇒ Object
35 36 37 |
# File 'lib/edifunct/segment_group.rb', line 35 def lookup_groups(segment_group_tag) @child_segment_group_map[segment_group_tag] end |
#lookup_segment(segment_tag, &block) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/edifunct/segment_group.rb', line 47 def lookup_segment(segment_tag, &block) if block_given? lookup_segments(segment_tag).find(&block) else lookup_segments(segment_tag).first end end |
#lookup_segments(segment_tag) ⇒ Object
43 44 45 |
# File 'lib/edifunct/segment_group.rb', line 43 def lookup_segments(segment_tag) @child_segment_map[segment_tag] end |
#print_with_structure ⇒ Object
55 56 57 |
# File 'lib/edifunct/segment_group.rb', line 55 def print_with_structure _print_with_structure(self) end |