# File lib/regin/group.rb, line 5 def initialize(expression, options = {}) @quantifier = @index = @name = nil @capture = true @expression = expression.dup(options) @quantifier = options[:quantifier] if options.key?(:quantifier) @capture = options[:capture] if options.key?(:capture) @index = options[:index] if options.key?(:index) @name = options[:name] if options.key?(:name) end
# File lib/regin/group.rb, line 63 def capture? capture end
# File lib/regin/group.rb, line 43 def dup(options = {}) original_options = option_names.inject({}) do |h, m| h[m.to_sym] = send(m) h end self.class.new(expression, original_options.merge(options)) end
# File lib/regin/group.rb, line 59 def include?(char) expression.include?(char) end
Returns true if expression could be treated as a literal string.
A Group is literal if its expression is literal and it has no quantifier.
# File lib/regin/group.rb, line 23 def literal? quantifier.nil? && expression.literal? end
# File lib/regin/group.rb, line 55 def match(char) to_regexp.match(char) end
# File lib/regin/group.rb, line 16 def option_names %w( quantifier capture index name ) end
# File lib/regin/group.rb, line 37 def to_regexp(anchored = false) re = to_s re = "\\A#{re}\\Z" if anchored Regexp.compile(re) end
# File lib/regin/group.rb, line 27 def to_s(parent = false) if !expression.options? "(#{capture ? '' : '?:'}#{expression.to_s(parent)})#{quantifier}" elsif capture == false "#{expression.to_s}#{quantifier}" else "(#{expression.to_s})#{quantifier}" end end