Class: Raabro::Input
- Inherits:
-
Object
- Object
- Raabro::Input
- Defined in:
- lib/raabro.rb
Instance Attribute Summary collapse
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#string ⇒ Object
Returns the value of attribute string.
Instance Method Summary collapse
- #at(i) ⇒ Object
-
#initialize(string, offset = 0, options = {}) ⇒ Input
constructor
A new instance of Input.
- #match(str_or_regex) ⇒ Object
- #tring(l = -1)) ⇒ Object
Constructor Details
#initialize(string, offset = 0, options = {}) ⇒ Input
11 12 13 14 15 16 |
# File 'lib/raabro.rb', line 11 def initialize(string, offset=0, ={}) @string = string @offset = offset.is_a?(Hash) ? 0 : offset @options = offset.is_a?(Hash) ? offset : end |
Instance Attribute Details
#offset ⇒ Object
Returns the value of attribute offset.
8 9 10 |
# File 'lib/raabro.rb', line 8 def offset @offset end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/raabro.rb', line 9 def @options end |
#string ⇒ Object
Returns the value of attribute string.
8 9 10 |
# File 'lib/raabro.rb', line 8 def string @string end |
Instance Method Details
#at(i) ⇒ Object
35 36 37 38 |
# File 'lib/raabro.rb', line 35 def at(i) @string[i, 1] end |
#match(str_or_regex) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/raabro.rb', line 18 def match(str_or_regex) if str_or_regex.is_a?(Regexp) m = @string[@offset..-1].match(str_or_regex) m && (m.offset(0).first == 0) ? m[0].length : false else # String or whatever responds to #to_s s = str_or_regex.to_s l = s.length @string[@offset, l] == s ? l : false end end |
#tring(l = -1)) ⇒ Object
30 31 32 33 |
# File 'lib/raabro.rb', line 30 def tring(l=-1) l < 0 ? @string[@offset..l] : @string[@offset, l] end |