Class: EacRubyUtils::RegexpParser
- Defined in:
- lib/eac_ruby_utils/regexp_parser.rb
Instance Attribute Summary collapse
-
#builder_proc ⇒ Object
readonly
Returns the value of attribute builder_proc.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#initialize(pattern, &builder_proc) ⇒ RegexpParser
constructor
A new instance of RegexpParser.
- #parse(string) ⇒ Object
- #parse!(string) ⇒ Object
- #parse?(string) ⇒ Boolean
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_proc ⇒ Object (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 |
#pattern ⇒ Object (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
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
24 25 26 |
# File 'lib/eac_ruby_utils/regexp_parser.rb', line 24 def parse?(string) internal_parse(string).first end |