Class: SourceMap::Offset
- Includes:
- Comparable
- Defined in:
- opal/stdlib/source_map/offset.rb
Overview
Public: Offset is an immutable structure representing a position in a source file.
Instance Attribute Summary collapse
- 
  
    
      #column  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Public: Get Integer column of offset. 
- 
  
    
      #line  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Public: Gets Integer line of offset. 
Class Method Summary collapse
- 
  
    
      .new(*args)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Public: Construct Offset value. 
Instance Method Summary collapse
- 
  
    
      #+(other)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Public: Shift the offset by some value. 
- 
  
    
      #<=>(other)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Public: Compare Offset to another. 
- 
  
    
      #initialize(line, column)  ⇒ Offset 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Public: Initialize an Offset. 
- 
  
    
      #inspect  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Public: Get a pretty inspect output for debugging purposes. 
- 
  
    
      #to_s  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Public: Get a simple string representation of the offset. 
Constructor Details
#initialize(line, column) ⇒ Offset
Public: Initialize an Offset.
line - Integer line number column - Integer column number
| 25 26 27 | # File 'opal/stdlib/source_map/offset.rb', line 25 def initialize(line, column) @line, @column = line, column end | 
Instance Attribute Details
#column ⇒ Object (readonly)
Public: Get Integer column of offset
| 33 34 35 | # File 'opal/stdlib/source_map/offset.rb', line 33 def column @column end | 
#line ⇒ Object (readonly)
Public: Gets Integer line of offset
| 30 31 32 | # File 'opal/stdlib/source_map/offset.rb', line 30 def line @line end | 
Class Method Details
Instance Method Details
#+(other) ⇒ Object
Public: Shift the offset by some value.
other - An Offset to add by its line and column Or an Integer to add by line
Returns a new Offset instance.
| 41 42 43 44 45 46 47 48 49 50 | # File 'opal/stdlib/source_map/offset.rb', line 41 def +(other) case other when Offset Offset.new(self.line + other.line, self.column + other.column) when Integer Offset.new(self.line + other, self.column) else raise ArgumentError, "can't convert #{other} into #{self.class}" end end | 
#<=>(other) ⇒ Object
Public: Compare Offset to another.
Useful for determining if a position in a few is between two offsets.
other - Another Offset
Returns a negative number when other is smaller and a positive number when its greater. Implements the Comparable#<=> protocol.
| 60 61 62 63 64 65 66 67 68 | # File 'opal/stdlib/source_map/offset.rb', line 60 def <=>(other) case other when Offset diff = self.line - other.line diff.zero? ? self.column - other.column : diff else raise ArgumentError, "can't convert #{other.class} into #{self.class}" end end | 
#inspect ⇒ Object
Public: Get a pretty inspect output for debugging purposes.
Returns a String.
| 84 85 86 | # File 'opal/stdlib/source_map/offset.rb', line 84 def inspect "#<#{self.class} line=#{line}, column=#{column}>" end | 
#to_s ⇒ Object
Public: Get a simple string representation of the offset
Returns a String.
| 73 74 75 76 77 78 79 | # File 'opal/stdlib/source_map/offset.rb', line 73 def to_s if column == 0 "#{line}" else "#{line}:#{column}" end end |