Module: RGFA::Segments
- Included in:
- RGFA
- Defined in:
- lib/rgfa/segments.rb
Overview
Methods for the RGFA class, which allow to handle segments in the graph.
Instance Method Summary collapse
-
#connected_segments(segment) ⇒ Array<String>
List of names of segments connected to
segment
by links or containments. -
#delete_segment(s, cascade = true) ⇒ RGFA
Delete a segment from the RGFA graph.
-
#segment(s) ⇒ RGFA::Line::Segment?
Searches the segment with name equal to
segment_name
. -
#segment!(s) ⇒ RGFA::Line::Segment
Searches the segment with name equal to
segment_name
. -
#segments ⇒ Array<RGFA::Line::Segment>
All segment lines of the graph.
-
#unconnect_segments(segment1, segment2) ⇒ RGFA
Delete all links/containments involving two segments.
Instance Method Details
#connected_segments(segment) ⇒ Array<String>
Returns list of names of segments connected to segment
by links or containments.
77 78 79 80 81 82 |
# File 'lib/rgfa/segments.rb', line 77 def connected_segments(segment) (neighbours([segment, :B]).map{|s, e| s} + neighbours([segment, :E]).map{|s, e| s} + contained_in(segment).map{|c| c.to} + containing(segment).map{|c| c.from}).uniq end |
#delete_segment(s, cascade = true) ⇒ RGFA
Delete a segment from the RGFA graph
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rgfa/segments.rb', line 34 def delete_segment(s, cascade=true) s = segment!(s) if cascade connected_segments(s).each {|cs| unconnect_segments(s, cs)} [:+, :-].each do |o| s.paths[o].each {|pt| delete_path(pt)} end end @segments.delete(s.name) return self end |
#segment(s) ⇒ RGFA::Line::Segment?
Searches the segment with name equal to segment_name
.
58 59 60 61 |
# File 'lib/rgfa/segments.rb', line 58 def segment(s) return s if s.kind_of?(RGFA::Line) @segments[s.to_sym] end |
#segment!(s) ⇒ RGFA::Line::Segment
Searches the segment with name equal to segment_name
.
65 66 67 68 69 70 71 72 73 |
# File 'lib/rgfa/segments.rb', line 65 def segment!(s) seg = segment(s) if seg.nil? raise RGFA::LineMissingError, "No segment has name #{s}"+ "#{segment_names.size < 10 ? "\nSegment names: "+segment_names.inspect : ''}" end seg end |
#segments ⇒ Array<RGFA::Line::Segment>
All segment lines of the graph
48 49 50 |
# File 'lib/rgfa/segments.rb', line 48 def segments @segments.values end |
#unconnect_segments(segment1, segment2) ⇒ RGFA
Delete all links/containments involving two segments
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rgfa/segments.rb', line 88 def unconnect_segments(segment1, segment2) containments_between(segment1, segment2).each {|c| delete_containment(c)} containments_between(segment2, segment1).each {|c| delete_containment(c)} [[:B, :E], [:B, :B], [:E, :B], [:E, :E]].each do |end1, end2| links_between([segment1, end1], [segment2, end2]).each do |l| delete_link(l) end end return self end |