Class: AePageObjects::RakeRouter::Param

Inherits:
Struct
  • Object
show all
Includes:
Comparable
Defined in:
lib/ae_page_objects/core/rake_router.rb

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object



100
101
102
# File 'lib/ae_page_objects/core/rake_router.rb', line 100

def <=>(other)
  name.to_s <=> other.name.to_s
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/ae_page_objects/core/rake_router.rb', line 104

def eql?(other)
  name == other.name
end

#hashObject



108
109
110
# File 'lib/ae_page_objects/core/rake_router.rb', line 108

def hash
  name.hash
end

#optional?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/ae_page_objects/core/rake_router.rb', line 96

def optional?
  optional
end

#replace_param_in_url(url) ⇒ Object



112
113
114
115
116
117
118
# File 'lib/ae_page_objects/core/rake_router.rb', line 112

def replace_param_in_url(url)
  if optional?
    url.gsub("(/:#{name})", '(\/.+)?')
  else
    url.gsub(":#{name}", '(.+)')
  end
end

#substitute(url, values) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/ae_page_objects/core/rake_router.rb', line 120

def substitute(url, values)
  if optional?
    if values[name]
      url.sub("(/:#{name})", "/#{values[name]}")
    else
      url.sub("(/:#{name})", '')
    end
  else
    raise ArgumentError, "Missing required parameter '#{name}' for '#{url}' in #{values.inspect}" unless values.key? name
    url.sub(":#{name}", values[name])
  end
end