Class: LintFu::FileRange
- Inherits:
-
Object
- Object
- LintFu::FileRange
- Defined in:
- lib/lint_fu/file_range.rb
Constant Summary collapse
- NONE =
FileRange.new('/dev/null', 0)
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#max_line ⇒ Object
readonly
Returns the value of attribute max_line.
-
#min_line ⇒ Object
readonly
Returns the value of attribute min_line.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #content ⇒ Object
- #include?(range) ⇒ Boolean
-
#initialize(filename, min_line, max_line = nil, content = nil) ⇒ FileRange
constructor
A new instance of FileRange.
- #line ⇒ Object
Constructor Details
#initialize(filename, min_line, max_line = nil, content = nil) ⇒ FileRange
Returns a new instance of FileRange.
5 6 7 8 9 10 |
# File 'lib/lint_fu/file_range.rb', line 5 def initialize(filename, min_line, max_line=nil, content=nil) @filename = File.(filename) @min_line = min_line @max_line = max_line || min_line @content = content end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
3 4 5 |
# File 'lib/lint_fu/file_range.rb', line 3 def filename @filename end |
#max_line ⇒ Object (readonly)
Returns the value of attribute max_line.
3 4 5 |
# File 'lib/lint_fu/file_range.rb', line 3 def max_line @max_line end |
#min_line ⇒ Object (readonly)
Returns the value of attribute min_line.
3 4 5 |
# File 'lib/lint_fu/file_range.rb', line 3 def min_line @min_line end |
Instance Method Details
#==(other) ⇒ Object
29 30 31 32 33 |
# File 'lib/lint_fu/file_range.rb', line 29 def ==(other) (self.filename == other.filename) && (self.min_line == other.min_line) && (self.max_line == other.max_line) end |
#content ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/lint_fu/file_range.rb', line 16 def content unless @content #TODO optimize all_content = File.readlines(self.file) min_line = [self.min_line - 1, 0].max max_line = [self.max_line - 1, all_content.size - 1].max @content = all_content[min_line..max_line] end return @content end |
#include?(range) ⇒ Boolean
35 36 37 38 39 |
# File 'lib/lint_fu/file_range.rb', line 35 def include?(range) (self.filename == range.filename) && (self.min_line <= range.min_line) && (self.max_line >= range.max_line) end |
#line ⇒ Object
12 13 14 |
# File 'lib/lint_fu/file_range.rb', line 12 def line min_line end |