Class: CodeMiner::SourceExtract

Inherits:
Object
  • Object
show all
Defined in:
lib/codeminer/source_extract.rb

Defined Under Namespace

Modules: Usage Classes: Partial

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src, line, column, end_line = nil, end_column = nil) ⇒ SourceExtract

Returns a new instance of SourceExtract.



95
96
97
98
99
100
101
# File 'lib/codeminer/source_extract.rb', line 95

def initialize(src, line, column, end_line=nil, end_column=nil)
  @src = src
  @line = line
  @column = column
  @end_line = end_line
  @end_column = end_column
end

Instance Attribute Details

#columnObject

Returns the value of attribute column.



5
6
7
# File 'lib/codeminer/source_extract.rb', line 5

def column
  @column
end

#end_columnObject

Returns the value of attribute end_column.



6
7
8
# File 'lib/codeminer/source_extract.rb', line 6

def end_column
  @end_column
end

#end_lineObject

Returns the value of attribute end_line.



6
7
8
# File 'lib/codeminer/source_extract.rb', line 6

def end_line
  @end_line
end

#lineObject

Returns the value of attribute line.



5
6
7
# File 'lib/codeminer/source_extract.rb', line 5

def line
  @line
end

Class Method Details

.extract_by_token(src, token, end_line, end_column) ⇒ Object



87
88
89
# File 'lib/codeminer/source_extract.rb', line 87

def self.extract_by_token(src, token, end_line, end_column)
  new(src, token.line, token.column, end_line, end_column)
end

.extract_by_tokens(src, token, end_token) ⇒ Object



91
92
93
# File 'lib/codeminer/source_extract.rb', line 91

def self.extract_by_tokens(src, token, end_token)
  new(src, token.line, token.column, end_token.end_line, end_token.end_column)
end

Instance Method Details

#adjust(other) ⇒ Object



108
109
110
# File 'lib/codeminer/source_extract.rb', line 108

def adjust(other)
  self.class.new(@src, line, column, other.end_line, other.end_column)
end

#extractObject



103
104
105
106
# File 'lib/codeminer/source_extract.rb', line 103

def extract
  lines = extract_lines(line-1..end_line-1).join
  lines.slice(column, lines.length - (lines.lines.last.length - end_column) - column).to_s.chomp
end