Class: RDocRuboCop::RDoc::RubySnippet
- Inherits:
-
Object
- Object
- RDocRuboCop::RDoc::RubySnippet
- Defined in:
- lib/rdoc_rubocop/rdoc/ruby_snippet.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Instance Method Summary collapse
- #append(line) ⇒ Object
- #build_file_path(filename) ⇒ Object
- #corrected_text_with_indent ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ RubySnippet
constructor
A new instance of RubySnippet.
- #lineno ⇒ Object
- #number_of_lines ⇒ Object
- #text ⇒ Object
- #trim! ⇒ Object
Constructor Details
#initialize ⇒ RubySnippet
Returns a new instance of RubySnippet.
12 13 14 |
# File 'lib/rdoc_rubocop/rdoc/ruby_snippet.rb', line 12 def initialize @lines = [] end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
10 11 12 |
# File 'lib/rdoc_rubocop/rdoc/ruby_snippet.rb', line 10 def file_path @file_path end |
Instance Method Details
#append(line) ⇒ Object
16 17 18 |
# File 'lib/rdoc_rubocop/rdoc/ruby_snippet.rb', line 16 def append(line) @lines << line end |
#build_file_path(filename) ⇒ Object
44 45 46 |
# File 'lib/rdoc_rubocop/rdoc/ruby_snippet.rb', line 44 def build_file_path(filename) @file_path = FilePath.new(filename, self) end |
#corrected_text_with_indent ⇒ Object
48 49 50 51 52 53 |
# File 'lib/rdoc_rubocop/rdoc/ruby_snippet.rb', line 48 def corrected_text_with_indent return unless @file_path indent = text_with_indent.indent @file_path.source.gsub(/^( *)(?=\S)/, "#{indent}\\1") end |
#empty? ⇒ Boolean
20 21 22 |
# File 'lib/rdoc_rubocop/rdoc/ruby_snippet.rb', line 20 def empty? @lines.empty? end |
#lineno ⇒ Object
36 37 38 |
# File 'lib/rdoc_rubocop/rdoc/ruby_snippet.rb', line 36 def lineno @lineno ||= @lines.map(&:lineno).minmax end |
#number_of_lines ⇒ Object
40 41 42 |
# File 'lib/rdoc_rubocop/rdoc/ruby_snippet.rb', line 40 def number_of_lines lineno[1] - lineno[0] + 1 end |
#text ⇒ Object
32 33 34 |
# File 'lib/rdoc_rubocop/rdoc/ruby_snippet.rb', line 32 def text text_with_indent.strip_indent end |
#trim! ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/rdoc_rubocop/rdoc/ruby_snippet.rb', line 24 def trim! i = @lines.size - 1 while i >= 0 && @lines[i].blank? do @lines.delete_at(i) i -= 1 end end |