Class: Neg::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/neg/input.rb

Instance Method Summary collapse

Constructor Details

#initialize(s) ⇒ Input

Returns a new instance of Input.



35
36
37
38
39
# File 'lib/neg/input.rb', line 35

def initialize(s)

  @s = s
  rewind
end

Instance Method Details

#eoi?Boolean

Returns:

  • (Boolean)


76
77
78
79
# File 'lib/neg/input.rb', line 76

def eoi?

  @offset >= @s.length
end

#positionObject



71
72
73
74
# File 'lib/neg/input.rb', line 71

def position

  [ @offset, @line, @column ]
end

#read(count) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/neg/input.rb', line 41

def read(count)

  s = ''

  count.times do

    c = @s[@offset, 1]

    break if c.nil?

    s << c

    @offset = @offset + 1

    if c == "\n"
      @line = @line + 1
      @column = 0
    else
      @column = @column + 1
    end
  end

  s
end

#remainsObject



81
82
83
84
85
86
# File 'lib/neg/input.rb', line 81

def remains

  rem = read(7)

  rem.length >= 7 ? rem = rem + '...' : rem
end

#rewind(pos = [ 0, 1, 1 ]) ⇒ Object



66
67
68
69
# File 'lib/neg/input.rb', line 66

def rewind(pos=[ 0, 1, 1 ])

  @offset, @line, @column = pos
end