class Mustermann::SimpleMatch

Fakes MatchData for patterns that do not support capturing. @see ruby-doc.org/core-2.0/MatchData.html MatchData

Public Class Methods

new(string = "", names: [], captures: []) click to toggle source

@api private

# File lib/mustermann/simple_match.rb, line 6
def initialize(string = "", names: [], captures: [])
  @string   = string.dup
  @names    = names
  @captures = captures
end

Public Instance Methods

+(other) click to toggle source

@!visibility private

# File lib/mustermann/simple_match.rb, line 37
def +(other)
  SimpleMatch.new(@string + other.to_s,
      names:    @names    + other.names,
      captures: @captures + other.captures)
end
[](*args) click to toggle source

@return [nil] imitates MatchData interface

# File lib/mustermann/simple_match.rb, line 28
def [](*args)
  args.map! do |arg|
    next arg unless arg.is_a? Symbol or arg.is_a? String
    names.index(arg.to_s)
  end
  @captures[*args]
end
captures() click to toggle source

@return [Array<String>] empty array for imitating MatchData interface

# File lib/mustermann/simple_match.rb, line 23
def captures
  @captures.dup
end
inspect() click to toggle source

@return [String] string representation

# File lib/mustermann/simple_match.rb, line 44
def inspect
  "#<%p %p>" % [self.class, @string]
end
names() click to toggle source

@return [Array<String>] empty array for imitating MatchData interface

# File lib/mustermann/simple_match.rb, line 18
def names
  @names.dup
end
to_s() click to toggle source

@return [String] the string that was matched against

# File lib/mustermann/simple_match.rb, line 13
def to_s
  @string.dup
end