Class: Percept::LineCollection
- Inherits:
-
Object
- Object
- Percept::LineCollection
- Includes:
- Enumerable
- Defined in:
- lib/percept/line_collection.rb
Instance Attribute Summary collapse
-
#lines ⇒ Object
Returns the value of attribute lines.
Instance Method Summary collapse
- #<<(new_line) ⇒ Object
- #[](index) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #filtered ⇒ Object
- #first ⇒ Object
-
#initialize(lines = []) ⇒ LineCollection
constructor
A new instance of LineCollection.
- #last ⇒ Object
- #line_filter ⇒ Object
- #merge!(other) ⇒ Object
- #merge_line(new_line) ⇒ Object
- #remove_short_lines! ⇒ Object
- #remove_unwanted_lines! ⇒ Object
- #size ⇒ Object (also: #length)
- #split ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(lines = []) ⇒ LineCollection
Returns a new instance of LineCollection.
9 10 11 |
# File 'lib/percept/line_collection.rb', line 9 def initialize(lines = []) self.lines = lines end |
Instance Attribute Details
#lines ⇒ Object
Returns the value of attribute lines.
7 8 9 |
# File 'lib/percept/line_collection.rb', line 7 def lines @lines end |
Instance Method Details
#<<(new_line) ⇒ Object
13 14 15 |
# File 'lib/percept/line_collection.rb', line 13 def <<(new_line) merge_line(new_line) || lines << new_line end |
#[](index) ⇒ Object
58 59 60 |
# File 'lib/percept/line_collection.rb', line 58 def [](index) lines[index] end |
#each ⇒ Object
46 47 48 |
# File 'lib/percept/line_collection.rb', line 46 def each lines.each { |line| yield(line) } end |
#empty? ⇒ Boolean
66 67 68 |
# File 'lib/percept/line_collection.rb', line 66 def empty? lines.empty? end |
#filtered ⇒ Object
78 79 80 |
# File 'lib/percept/line_collection.rb', line 78 def filtered self.class.new(lines.select { |line| !line_filter.filter_line?(line) }) end |
#first ⇒ Object
50 51 52 |
# File 'lib/percept/line_collection.rb', line 50 def first lines.first end |
#last ⇒ Object
54 55 56 |
# File 'lib/percept/line_collection.rb', line 54 def last lines.last end |
#line_filter ⇒ Object
82 83 84 |
# File 'lib/percept/line_collection.rb', line 82 def line_filter LineFilter.new end |
#merge!(other) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/percept/line_collection.rb', line 17 def merge!(other) other.lines.each do |line| self << line end self end |
#merge_line(new_line) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/percept/line_collection.rb', line 32 def merge_line(new_line) old_line = lines.detect { |line| line =~ new_line } return unless old_line old_line.merge!(new_line) true end |
#remove_short_lines! ⇒ Object
74 75 76 |
# File 'lib/percept/line_collection.rb', line 74 def remove_short_lines! lines.delete_if(&:short?) end |
#remove_unwanted_lines! ⇒ Object
70 71 72 |
# File 'lib/percept/line_collection.rb', line 70 def remove_unwanted_lines! lines.delete_if { |line| line_filter.filter_line?(line) } end |
#size ⇒ Object Also known as: length
41 42 43 |
# File 'lib/percept/line_collection.rb', line 41 def size lines.size end |
#split ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/percept/line_collection.rb', line 24 def split collection = self.class.new lines.each do |line| collection.merge!(line.split) end collection end |
#to_s ⇒ Object
62 63 64 |
# File 'lib/percept/line_collection.rb', line 62 def to_s lines.map(&:to_s).to_s end |