Class: Maccro::CodeRange
- Inherits:
-
Object
- Object
- Maccro::CodeRange
- Defined in:
- lib/maccro/code_range.rb
Instance Attribute Summary collapse
-
#first_column ⇒ Object
readonly
Returns the value of attribute first_column.
-
#first_lineno ⇒ Object
readonly
Returns the value of attribute first_lineno.
-
#last_column ⇒ Object
readonly
Returns the value of attribute last_column.
-
#last_lineno ⇒ Object
readonly
Returns the value of attribute last_lineno.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #get(source) ⇒ Object
-
#initialize(first_lineno, first_column, last_lineno, last_column) ⇒ CodeRange
constructor
A new instance of CodeRange.
- #source(path) ⇒ Object
Constructor Details
#initialize(first_lineno, first_column, last_lineno, last_column) ⇒ CodeRange
Returns a new instance of CodeRange.
11 12 13 14 15 16 |
# File 'lib/maccro/code_range.rb', line 11 def initialize(first_lineno, first_column, last_lineno, last_column) @first_lineno = first_lineno @first_column = first_column @last_lineno = last_lineno @last_column = last_column end |
Instance Attribute Details
#first_column ⇒ Object (readonly)
Returns the value of attribute first_column.
9 10 11 |
# File 'lib/maccro/code_range.rb', line 9 def first_column @first_column end |
#first_lineno ⇒ Object (readonly)
Returns the value of attribute first_lineno.
9 10 11 |
# File 'lib/maccro/code_range.rb', line 9 def first_lineno @first_lineno end |
#last_column ⇒ Object (readonly)
Returns the value of attribute last_column.
9 10 11 |
# File 'lib/maccro/code_range.rb', line 9 def last_column @last_column end |
#last_lineno ⇒ Object (readonly)
Returns the value of attribute last_lineno.
9 10 11 |
# File 'lib/maccro/code_range.rb', line 9 def last_lineno @last_lineno end |
Class Method Details
Instance Method Details
#<=>(other) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/maccro/code_range.rb', line 25 def <=>(other) if @first_lineno < other.first_lineno -1 elsif @first_lineno == other.first_lineno if @first_column < other.first_column -1 elsif @first_column == other.first_column if @last_lineno < other.last_lineno -1 elsif @last_lineno == other.last_lineno if @last_column < other.last_column -1 elsif @last_column == other.last_column 0 else # @last_column > other.last_column 1 end else # @last_lineno > other.last_lineno 1 end else # @first_column > other.first_column 1 end else # @first_lineno > other.first_lineno 1 end end |
#==(other) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/maccro/code_range.rb', line 18 def ==(other) @first_lineno == other.first_lineno && @first_column == other.first_column && @last_lineno == other.last_lineno && @last_column == other.last_column end |
#get(source) ⇒ Object
58 59 60 61 |
# File 'lib/maccro/code_range.rb', line 58 def get(source) range = CodeUtil.code_range_to_range(source, self) source[range] end |
#source(path) ⇒ Object
53 54 55 56 |
# File 'lib/maccro/code_range.rb', line 53 def source(path) source = File.open(path){|f| f.read } # open as binary? get(source) end |