Class: PerseusMatch::Token

Inherits:
String
  • Object
show all
Defined in:
lib/perseus_match/token.rb

Constant Summary collapse

WC_RE =
%r{[/|]([^/|]*)\z}
ANY_WC =
'*'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from String

#downcase, #downcase!

Constructor Details

#initialize(form, wc = nil) ⇒ Token

Returns a new instance of Token.



11
12
13
14
15
16
# File 'lib/perseus_match/token.rb', line 11

def initialize(form, wc = nil)
  @form = form.sub(WC_RE, '')
  @wc   = wc || $1

  super(@form)
end

Instance Attribute Details

#formObject (readonly)

Returns the value of attribute form.



9
10
11
# File 'lib/perseus_match/token.rb', line 9

def form
  @form
end

#wcObject (readonly)

Returns the value of attribute wc.



9
10
11
# File 'lib/perseus_match/token.rb', line 9

def wc
  @wc
end

Instance Method Details

#==(other) ⇒ Object



27
28
29
# File 'lib/perseus_match/token.rb', line 27

def ==(other)
  other.is_a?(self.class) ? form == other.form : form == other
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/perseus_match/token.rb', line 31

def eql?(other)
  self == other && wc == other.wc
end

#inspectObject Also known as: to_s



35
36
37
# File 'lib/perseus_match/token.rb', line 35

def inspect
  "#{super}/#{wc}"
end

#match?(wcs) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/perseus_match/token.rb', line 18

def match?(wcs)
  wcs = [*wcs].compact
  wcs.include?(wc) || wcs.include?(ANY_WC)
end

#unk?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/perseus_match/token.rb', line 23

def unk?
  wc == '?'
end