Class: 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



130
131
132
133
# File 'Library/Homebrew/dev-cmd/audit.rb', line 130

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

Instance Method Details

#=~(other) ⇒ Object



151
152
153
# File 'Library/Homebrew/dev-cmd/audit.rb', line 151

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

#data?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'Library/Homebrew/dev-cmd/audit.rb', line 139

def data?
  /^[^#]*\bDATA\b/ =~ @text
end

#end?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'Library/Homebrew/dev-cmd/audit.rb', line 143

def end?
  /^__END__$/ =~ @text
end

#include?(s) ⇒ Boolean

Returns:

  • (Boolean)


155
156
157
# File 'Library/Homebrew/dev-cmd/audit.rb', line 155

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

#line_number(regex, skip = 0) ⇒ Object



159
160
161
162
# File 'Library/Homebrew/dev-cmd/audit.rb', line 159

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

#reverse_line_number(regex) ⇒ Object



164
165
166
167
# File 'Library/Homebrew/dev-cmd/audit.rb', line 164

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

#trailing_newline?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'Library/Homebrew/dev-cmd/audit.rb', line 147

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

#without_patchObject



135
136
137
# File 'Library/Homebrew/dev-cmd/audit.rb', line 135

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