Class: Stupidedi::Reader::Position
- Inherits:
-
Object
- Object
- Stupidedi::Reader::Position
- Defined in:
- lib/stupidedi/reader/position.rb
Instance Attribute Summary collapse
- #column ⇒ Integer readonly
- #line ⇒ Integer readonly
- #offset ⇒ Integer readonly
- #path ⇒ String, Pathname readonly
Class Method Summary collapse
Instance Method Summary collapse
- #copy(changes = {})
-
#initialize(offset, line, column, path) ⇒ Position
constructor
A new instance of Position.
- #inspect ⇒ String
- #pretty_print(q)
- #to_s
Constructor Details
#initialize(offset, line, column, path) ⇒ Position
Returns a new instance of Position.
19 20 21 22 |
# File 'lib/stupidedi/reader/position.rb', line 19 def initialize(offset, line, column, path) @offset, @line, @column, @path = offset, line, column, path end |
Instance Attribute Details
#column ⇒ Integer (readonly)
14 15 16 |
# File 'lib/stupidedi/reader/position.rb', line 14 def column @column end |
#line ⇒ Integer (readonly)
11 12 13 |
# File 'lib/stupidedi/reader/position.rb', line 11 def line @line end |
#offset ⇒ Integer (readonly)
8 9 10 |
# File 'lib/stupidedi/reader/position.rb', line 8 def offset @offset end |
#path ⇒ String, Pathname (readonly)
17 18 19 |
# File 'lib/stupidedi/reader/position.rb', line 17 def path @path end |
Class Method Details
Instance Method Details
#copy(changes = {})
24 25 26 27 28 29 30 |
# File 'lib/stupidedi/reader/position.rb', line 24 def copy(changes = {}) Position.new \ changes.fetch(:offset, @offset), changes.fetch(:line, @line), changes.fetch(:column, @column), changes.fetch(:path, @path) end |
#inspect ⇒ String
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/stupidedi/reader/position.rb', line 37 def inspect if @path.present? parts = ["file #{@path}", "line #{@line}"] else parts = ["line #{@line}"] end if @column.present? parts << "column #{@column}" end parts.join(", ") end |
#pretty_print(q)
This method returns an undefined value.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/stupidedi/reader/position.rb', line 52 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 |
#to_s
32 33 34 |
# File 'lib/stupidedi/reader/position.rb', line 32 def to_s inspect end |