Class: Sherlock::Collection::Lines
- Defined in:
- lib/sherlock/collection/lines.rb
Instance Method Summary collapse
-
#gsub(*args, &block) ⇒ Object
Executes gsub on all lines in the collection and returns the modified collection.
-
#matches ⇒ Object
Returns an array of the lines’ match_data objects without the ‘overall’ match (the first element of the MatchData object).
-
#new(arr, opts = {}) ⇒ Object
:nodoc:.
- #save! ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Methods inherited from Base
#&, #+, #-, #[], #first, #initialize, #select_items_matching, #|
Constructor Details
This class inherits a constructor from Sherlock::Collection::Base
Instance Method Details
#gsub(*args, &block) ⇒ Object
Executes gsub on all lines in the collection and returns the modified collection.
8 9 10 11 |
# File 'lib/sherlock/collection/lines.rb', line 8 def gsub(*args, &block) arr = map { |line| line.gsub(*args, &block) } new(arr) end |
#matches ⇒ Object
Returns an array of the lines’ match_data objects without the ‘overall’ match (the first element of the MatchData object).
15 16 17 |
# File 'lib/sherlock/collection/lines.rb', line 15 def matches map { |line| line.match_data[1..line.match_data.length-1] } end |
#new(arr, opts = {}) ⇒ Object
:nodoc:
19 20 21 |
# File 'lib/sherlock/collection/lines.rb', line 19 def new(arr, opts = {}) # :nodoc: self.class.new(arr) end |
#save! ⇒ Object
23 24 25 |
# File 'lib/sherlock/collection/lines.rb', line 23 def save! sort_by { |line| line.line_number }.reverse.each(&:save!) end |
#to_s ⇒ Object Also known as: inspect
27 28 29 |
# File 'lib/sherlock/collection/lines.rb', line 27 def to_s map { |line| (line.changed? ? '[C] ' : '[ ] ') + line.inspect }.join("\n") end |