Class: Gapic::PathTemplate::Segment
- Inherits:
-
Object
- Object
- Gapic::PathTemplate::Segment
- Defined in:
- lib/gapic/path_template/segment.rb
Overview
A segment in a URI path template.
Instance Attribute Summary collapse
-
#name ⇒ String, Integer
readonly
The name of a named segment, or the position of a positional segment.
-
#pattern ⇒ String?
readonly
The pattern of the segment, nil if not set.
Instance Method Summary collapse
-
#initialize(name, pattern) ⇒ Segment
constructor
A new instance of Segment.
-
#named? ⇒ Boolean
Determines if the segment is named (has a string for a name).
-
#pattern? ⇒ Boolean
Determines if the segment has a pattern.
-
#positional? ⇒ Boolean
Determines if the segment is positional (has a number for a name).
Constructor Details
#initialize(name, pattern) ⇒ Segment
Returns a new instance of Segment.
31 32 33 34 |
# File 'lib/gapic/path_template/segment.rb', line 31 def initialize name, pattern @name = name @pattern = pattern end |
Instance Attribute Details
#name ⇒ String, Integer (readonly)
Returns The name of a named segment, or the position of a positional segment.
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 60 61 62 63 64 65 |
# File 'lib/gapic/path_template/segment.rb', line 28 class Segment attr_reader :name, :pattern def initialize name, pattern @name = name @pattern = pattern end # Determines if the segment is positional (has a number for a name). # # @return [Boolean] def positional? name.is_a? Integer end # Determines if the segment is named (has a string for a name). # # @return [Boolean] def named? !positional? end # Determines if the segment has a pattern. Positional segments always # have a pattern. Named segments may have a pattern if provided in the # URI path template. # # @return [Boolean] def pattern? !@pattern.nil? end # @private def == other return false unless other.is_a? self.class (name == other.name) && (pattern == other.pattern) end end |
#pattern ⇒ String? (readonly)
Returns The pattern of the segment, nil if not set.
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 60 61 62 63 64 65 |
# File 'lib/gapic/path_template/segment.rb', line 28 class Segment attr_reader :name, :pattern def initialize name, pattern @name = name @pattern = pattern end # Determines if the segment is positional (has a number for a name). # # @return [Boolean] def positional? name.is_a? Integer end # Determines if the segment is named (has a string for a name). # # @return [Boolean] def named? !positional? end # Determines if the segment has a pattern. Positional segments always # have a pattern. Named segments may have a pattern if provided in the # URI path template. # # @return [Boolean] def pattern? !@pattern.nil? end # @private def == other return false unless other.is_a? self.class (name == other.name) && (pattern == other.pattern) end end |
Instance Method Details
#named? ⇒ Boolean
Determines if the segment is named (has a string for a name).
46 47 48 |
# File 'lib/gapic/path_template/segment.rb', line 46 def named? !positional? end |
#pattern? ⇒ Boolean
Determines if the segment has a pattern. Positional segments always have a pattern. Named segments may have a pattern if provided in the URI path template.
55 56 57 |
# File 'lib/gapic/path_template/segment.rb', line 55 def pattern? !@pattern.nil? end |
#positional? ⇒ Boolean
Determines if the segment is positional (has a number for a name).
39 40 41 |
# File 'lib/gapic/path_template/segment.rb', line 39 def positional? name.is_a? Integer end |