Class: Nit::Lines

Inherits:
Array
  • Object
show all
Defined in:
lib/nit/lines.rb

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Lines

Returns a new instance of Lines.



3
4
5
# File 'lib/nit/lines.rb', line 3

def initialize(text)
  super(text.split("\n").collect { |ln| Line.new(ln, self) })
end

Instance Method Details

#file_patternsObject

private



32
33
34
35
36
37
# File 'lib/nit/lines.rb', line 32

def file_patterns
  {
    modified: /#?\tmodified:(.+)/,
    new: /#?\t((?!modified:).+)/
  }
end

#filesObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/nit/lines.rb', line 15

def files
  files = []

  for type, pattern in file_patterns
    find(pattern) do |ln, matches|
      files << file = File.new(matches[1].strip, ln)
    end
  end

  files
end

#find(pattern) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/nit/lines.rb', line 7

def find(pattern)
  each do |ln|
    next unless matches = ln.match(pattern)

    yield ln, matches
  end
end

#to_sObject



27
28
29
# File 'lib/nit/lines.rb', line 27

def to_s
  join("\n")
end