Class: EacRubyUtils::RegexpParser

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_ruby_utils/regexp_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, &builder_proc) ⇒ RegexpParser

Returns a new instance of RegexpParser.



7
8
9
10
# File 'lib/eac_ruby_utils/regexp_parser.rb', line 7

def initialize(pattern, &builder_proc)
  @pattern = pattern
  @builder_proc = builder_proc
end

Instance Attribute Details

#builder_procObject (readonly)

Returns the value of attribute builder_proc.



5
6
7
# File 'lib/eac_ruby_utils/regexp_parser.rb', line 5

def builder_proc
  @builder_proc
end

#patternObject (readonly)

Returns the value of attribute pattern.



5
6
7
# File 'lib/eac_ruby_utils/regexp_parser.rb', line 5

def pattern
  @pattern
end

Instance Method Details

#parse(string) ⇒ Object



12
13
14
# File 'lib/eac_ruby_utils/regexp_parser.rb', line 12

def parse(string)
  internal_parse(string)[1]
end

#parse!(string) ⇒ Object

Raises:

  • (::ArgumentError)


16
17
18
19
20
21
# File 'lib/eac_ruby_utils/regexp_parser.rb', line 16

def parse!(string)
  match, result = internal_parse(string)
  return result if match

  raise ::ArgumentError, "String \"#{string}\" does not match pattern \"#{pattern}\""
end

#parse?(string) ⇒ Boolean

Returns:



24
25
26
# File 'lib/eac_ruby_utils/regexp_parser.rb', line 24

def parse?(string)
  internal_parse(string).first
end