Class: Rewrite::ByExample::UnionOfEntitiesSequence
- Defined in:
- lib/rewrite/by_example/union_of_entities_sequence.rb
Overview
–
Acts like a union of sequences but is initialized with entities. Could be better!
Instance Attribute Summary collapse
-
#length_range ⇒ Object
Returns the value of attribute length_range.
-
#matchers ⇒ Object
Returns the value of attribute matchers.
Instance Method Summary collapse
-
#initialize(*matchers) ⇒ UnionOfEntitiesSequence
constructor
A new instance of UnionOfEntitiesSequence.
- #range_union(range1, range2) ⇒ Object
- #to_s ⇒ Object
- #unfolders_by_length(length) ⇒ Object
Methods inherited from Sequence
Constructor Details
#initialize(*matchers) ⇒ UnionOfEntitiesSequence
16 17 18 19 20 21 |
# File 'lib/rewrite/by_example/union_of_entities_sequence.rb', line 16 def initialize(*matchers) self.matchers = matchers.map { |matcher| LengthOne.new(ObjectToMatcher.from_object(matcher)) } @length_range = @matchers.inject(0..0) { |range, matcher| range_union(range, matcher.length_range) } end |
Instance Attribute Details
#length_range ⇒ Object
Returns the value of attribute length_range.
14 15 16 |
# File 'lib/rewrite/by_example/union_of_entities_sequence.rb', line 14 def length_range @length_range end |
#matchers ⇒ Object
Returns the value of attribute matchers.
14 15 16 |
# File 'lib/rewrite/by_example/union_of_entities_sequence.rb', line 14 def matchers @matchers end |
Instance Method Details
#range_union(range1, range2) ⇒ Object
27 28 29 |
# File 'lib/rewrite/by_example/union_of_entities_sequence.rb', line 27 def range_union(range1, range2) ([range1.begin, range2.begin].min)..([range1.end, range2.end].max) end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/rewrite/by_example/union_of_entities_sequence.rb', line 31 def to_s "(#{matchers.map { |m| m.to_s }.join(' | ')})" end |
#unfolders_by_length(length) ⇒ Object
23 24 25 |
# File 'lib/rewrite/by_example/union_of_entities_sequence.rb', line 23 def unfolders_by_length(length) self.matchers.inject([]) { |unfolders, matcher| unfolders + matcher.unfolders_by_length(length) } end |