Class: CheckPlease::PathSegment

Inherits:
Object
  • Object
show all
Includes:
Reification
Defined in:
lib/check_please/path_segment.rb

Constant Summary collapse

KEY_EXPR =
%r{
  ^
  \:       # a literal colon
  (        # capture key
    [^\:]+ # followed by one or more things that aren't colons
  )        # end capture key
  $
}x
KEY_VAL_EXPR =
%r{
  ^
  (       # capture key
    [^=]+ # stuff (just not an equal sign)
  )       # end capture key
  \=      # an equal sign
  (       # capture key value
    [^=]+ # stuff (just not an equal sign)
  )       # end capture key value
  $
}x

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Reification

included

Constructor Details

#initialize(name = nil) ⇒ PathSegment

Returns a new instance of PathSegment.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/check_please/path_segment.rb', line 31

def initialize(name = nil)
  @name = name.to_s.strip

  case @name
  when "", /\s/ # blank or has any whitespace
    raise InvalidPathSegment, "#{name.inspect} is not a valid #{self.class} name"
  end

  parse_key_and_value
  freeze
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



28
29
30
# File 'lib/check_please/path_segment.rb', line 28

def key
  @key
end

#key_valueObject (readonly)

Returns the value of attribute key_value.



28
29
30
# File 'lib/check_please/path_segment.rb', line 28

def key_value
  @key_value
end

#nameObject (readonly) Also known as: to_s

Returns the value of attribute name.



28
29
30
# File 'lib/check_please/path_segment.rb', line 28

def name
  @name
end

Instance Method Details

#key_expr?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/check_please/path_segment.rb', line 43

def key_expr?
  name.match?(KEY_EXPR)
end

#key_val_expr?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/check_please/path_segment.rb', line 47

def key_val_expr?
  name.match?(KEY_VAL_EXPR)
end

#match?(other_segment_or_string) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
# File 'lib/check_please/path_segment.rb', line 51

def match?(other_segment_or_string)
  other = reify(other_segment_or_string)
  PathSegmentMatcher.call(self, other)
end

#splat?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/check_please/path_segment.rb', line 56

def splat?
  name == '*'
end