class Maccro::CodeRange
Attributes
first_column[R]
first_lineno[R]
last_column[R]
last_lineno[R]
Public Class Methods
from_node(ast)
click to toggle source
# File lib/maccro/code_range.rb, line 5 def self.from_node(ast) CodeRange.new(ast.first_lineno, ast.first_column, ast.last_lineno, ast.last_column) end
new(first_lineno, first_column, last_lineno, last_column)
click to toggle source
# 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
Public Instance Methods
<=>(other)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/maccro/code_range.rb, line 58 def get(source) range = CodeUtil.code_range_to_range(source, self) source[range] end
source(path)
click to toggle source
# File lib/maccro/code_range.rb, line 53 def source(path) source = File.open(path){|f| f.read } # open as binary? get(source) end