Sha256: af9b32183fb4df8723affde1c759a034d2424ab3591fad4bcb323de436f6d35d
Contents?: true
Size: 688 Bytes
Versions: 111
Compression:
Stored size: 688 Bytes
Contents
# frozen_string_literal: true module EacRubyUtils class RegexpParser attr_reader :pattern, :builder_proc def initialize(pattern, &builder_proc) @pattern = pattern @builder_proc = builder_proc end def parse(string) internal_parse(string)[1] end def parse!(string) match, result = internal_parse(string) return result if match raise ::ArgumentError, "String \"#{string}\" does not match pattern \"#{pattern}\"" end private def internal_parse(string) m = pattern.match(string) if m [true, builder_proc ? builder_proc.call(m) : m] else [false, nil] end end end end
Version data entries
111 entries across 111 versions & 4 rubygems