Class: Stupidedi::Reader::Position

Inherits:
Object
  • Object
show all
Includes:
Inspect
Defined in:
lib/stupidedi/reader/position.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(offset, line, column, path) ⇒ Position

Returns a new instance of Position.



23
24
25
26
# File 'lib/stupidedi/reader/position.rb', line 23

def initialize(offset, line, column, path)
  @offset, @line, @column, @path =
    offset, line, column, path
end

Instance Attribute Details

#columnInteger (readonly)

Returns:

  • (Integer)


18
19
20
# File 'lib/stupidedi/reader/position.rb', line 18

def column
  @column
end

#lineInteger (readonly)

Returns:

  • (Integer)


15
16
17
# File 'lib/stupidedi/reader/position.rb', line 15

def line
  @line
end

#offsetInteger (readonly)

Returns:

  • (Integer)


12
13
14
# File 'lib/stupidedi/reader/position.rb', line 12

def offset
  @offset
end

#pathString, Pathname (readonly)

Returns:

  • (String, Pathname)


21
22
23
# File 'lib/stupidedi/reader/position.rb', line 21

def path
  @path
end

Class Method Details

.caller(offset = 1) ⇒ Object



66
67
68
69
# File 'lib/stupidedi/reader/position.rb', line 66

def caller(offset = 1)
  path, line, method = Stupidedi.caller(offset + 1)
  new(nil, line, nil, path)
end

Instance Method Details

#copy(changes = {}) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/stupidedi/reader/position.rb', line 28

def copy(changes = {})
  Position.new \
    changes.fetch(:offset, @offset),
    changes.fetch(:line, @line),
    changes.fetch(:column, @column),
    changes.fetch(:path, @path)
end

#inspectString

Returns:

  • (String)


37
38
39
40
41
42
43
# File 'lib/stupidedi/reader/position.rb', line 37

def inspect
  if @path.present?
    "file #{@path}, line #{@line}, column #{@column}"
  else
    "line #{@line}, column #{@column}"
  end
end

#pretty_print(q) ⇒ void

This method returns an undefined value.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/stupidedi/reader/position.rb', line 46

def pretty_print(q)
  q.text "Position"
  q.group(2, "(", ")") do
    q.breakable ""
    q.text "line #{@line},"
    q.breakable
    q.text "column #{@column},"
    q.breakable
    q.text "offset #{@offset}"

    unless @path.nil?
      q.text ","
      q.breakable
      q.text "path #{@path}"
    end
  end
end