class CheckPlease::PathSegmentMatcher

Attributes

a[R]
b[R]
types[R]

Public Class Methods

call(a,b) click to toggle source
# File lib/check_please/path_segment_matcher.rb, line 4
def self.call(a,b)
  new(a,b).call
end
new(a, b) click to toggle source
# File lib/check_please/path_segment_matcher.rb, line 9
def initialize(a, b)
  @a, @b = a, b
  @types = [ _type(a), _type(b) ].sort
end

Public Instance Methods

call() click to toggle source
# File lib/check_please/path_segment_matcher.rb, line 14
def call
  return true             if either?(:splat)
  return a.name == b.name if both?(:plain)
  return a.key  == b.key  if key_and_key_value?

  false
end

Private Instance Methods

_type(x) click to toggle source
# File lib/check_please/path_segment_matcher.rb, line 24
def _type(x)
  return :splat     if x.splat?
  return :key       if x.key_expr?
  return :key_value if x.key_val_expr?
  :plain
end
both?(type) click to toggle source
# File lib/check_please/path_segment_matcher.rb, line 31
def both?(type)
  types.uniq == [type]
end
either?(type) click to toggle source
# File lib/check_please/path_segment_matcher.rb, line 35
def either?(type)
  types.include?(type)
end
key_and_key_value?() click to toggle source
# File lib/check_please/path_segment_matcher.rb, line 39
def key_and_key_value?
  types == [ :key, :key_value ]
end