Class: SyntaxTree::XML::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/xml/nodes.rb

Overview

A Location represents a position for a node in the source file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_char:, end_char:, start_line:, end_line:) ⇒ Location

Returns a new instance of Location.



9
10
11
12
13
14
# File 'lib/syntax_tree/xml/nodes.rb', line 9

def initialize(start_char:, end_char:, start_line:, end_line:)
  @start_char = start_char
  @end_char = end_char
  @start_line = start_line
  @end_line = end_line
end

Instance Attribute Details

#end_charObject (readonly)

Returns the value of attribute end_char.



7
8
9
# File 'lib/syntax_tree/xml/nodes.rb', line 7

def end_char
  @end_char
end

#end_lineObject (readonly)

Returns the value of attribute end_line.



7
8
9
# File 'lib/syntax_tree/xml/nodes.rb', line 7

def end_line
  @end_line
end

#start_charObject (readonly)

Returns the value of attribute start_char.



7
8
9
# File 'lib/syntax_tree/xml/nodes.rb', line 7

def start_char
  @start_char
end

#start_lineObject (readonly)

Returns the value of attribute start_line.



7
8
9
# File 'lib/syntax_tree/xml/nodes.rb', line 7

def start_line
  @start_line
end

Instance Method Details

#<=>(other) ⇒ Object



34
35
36
# File 'lib/syntax_tree/xml/nodes.rb', line 34

def <=>(other)
  start_char <=> other.start_char
end

#deconstruct_keys(keys) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/syntax_tree/xml/nodes.rb', line 16

def deconstruct_keys(keys)
  {
    start_char: start_char,
    end_char: end_char,
    start_line: start_line,
    end_line: end_line
  }
end

#to(other) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/syntax_tree/xml/nodes.rb', line 25

def to(other)
  Location.new(
    start_char: start_char,
    start_line: start_line,
    end_char: other.end_char,
    end_line: other.end_line
  )
end