Class: MetaParse::MetaScanner

Inherits:
StringScanner
  • Object
show all
Defined in:
lib/meta_parse.rb

Overview

End Interface

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, parser = nil) ⇒ MetaScanner

Returns a new instance of MetaScanner.



64
65
66
67
# File 'lib/meta_parse.rb', line 64

def initialize(string, parser=nil)
  super string
  @parser = parser
end

Instance Attribute Details

#parserObject

Returns the value of attribute parser.



62
63
64
# File 'lib/meta_parse.rb', line 62

def parser
  @parser
end

Instance Method Details

#match_char(char) ⇒ Object

This is a special case and could actually be handled by match_string if necessary.



70
71
72
73
74
75
76
# File 'lib/meta_parse.rb', line 70

def match_char(char)
  c = peek(1)
  if c == char
    self.pos += 1
    c
  end
end

#match_string(str, position2 = 0) ⇒ Object



78
79
80
81
82
83
# File 'lib/meta_parse.rb', line 78

def match_string(str, position2=0)
  if (string.equal_at(pos, str, position2))
    self.pos += str.length
    str
  end
end

#scan(spec) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/meta_parse.rb', line 85

def scan(spec)
  case spec
  when Regexp
    result = super spec
    matched
  when String
    if spec.length > 0
      match_string(spec)
    else
      match_char(spec)
    end
  end
end