Class: Gapic::PathTemplate::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/gapic/path_template/segment.rb

Overview

A segment in a URI path template.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Returns:

  • (String, Integer) —

    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.

Returns:

  • (String, nil) —

    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).

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)


39
40
41
# File 'lib/gapic/path_template/segment.rb', line 39

def positional?
  name.is_a? Integer
end