aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/vendor/rack-mount-0.6.6.pre/rack/mount/vendor/regin/regin/atom.rb
blob: eb1923a5a1f4654935a5a09f5498a1dc7034e93b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module Regin
  class Atom
    attr_reader :value, :ignorecase

    def initialize(value, options = {})
      @value = value
      @ignorecase = options[:ignorecase]
    end

    def option_names
      %w( ignorecase )
    end

    # Returns true if expression could be treated as a literal string.
    def literal?
      false
    end

    def casefold?
      ignorecase ? true : false
    end

    def dup(options = {})
      original_options = option_names.inject({}) do |h, m|
        h[m.to_sym] = send(m)
        h
      end
      self.class.new(value, original_options.merge(options))
    end

    def to_s(parent = false)
      "#{value}"
    end

    def inspect #:nodoc:
      "#<#{self.class.to_s.sub('Regin::', '')} #{to_s.inspect}>"
    end

    def ==(other) #:nodoc:
      case other
      when String
        other == to_s
      else
        eql?(other)
      end
    end

    def eql?(other) #:nodoc:
      other.instance_of?(self.class) &&
        self.value.eql?(other.value) &&
        (!!self.ignorecase).eql?(!!other.ignorecase)
    end

    def freeze #:nodoc:
      value.freeze
      super
    end
  end
end