Class: Homebrew::FormulaText

Inherits:
Object
  • Object
show all
Defined in:
Library/Homebrew/dev-cmd/audit.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FormulaText

Returns a new instance of FormulaText.


191
192
193
194
# File 'Library/Homebrew/dev-cmd/audit.rb', line 191

def initialize(path)
  @text = path.open("rb", &:read)
  @lines = @text.lines.to_a
end

Instance Method Details

#=~(other) ⇒ Object


204
205
206
# File 'Library/Homebrew/dev-cmd/audit.rb', line 204

def =~(other)
  other =~ @text
end

#include?(s) ⇒ Boolean

Returns:

  • (Boolean)

208
209
210
# File 'Library/Homebrew/dev-cmd/audit.rb', line 208

def include?(s)
  @text.include? s
end

#line_number(regex, skip = 0) ⇒ Object


212
213
214
215
# File 'Library/Homebrew/dev-cmd/audit.rb', line 212

def line_number(regex, skip = 0)
  index = @lines.drop(skip).index { |line| line =~ regex }
  index ? index + 1 : nil
end

#reverse_line_number(regex) ⇒ Object


217
218
219
220
# File 'Library/Homebrew/dev-cmd/audit.rb', line 217

def reverse_line_number(regex)
  index = @lines.reverse.index { |line| line =~ regex }
  index ? @lines.count - index : nil
end

#trailing_newline?Boolean

Returns:

  • (Boolean)

200
201
202
# File 'Library/Homebrew/dev-cmd/audit.rb', line 200

def trailing_newline?
  /\Z\n/ =~ @text
end

#without_patchObject


196
197
198
# File 'Library/Homebrew/dev-cmd/audit.rb', line 196

def without_patch
  @text.split("\n__END__").first
end