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



102
103
104
# File 'lib/ae_page_objects/core/rake_router.rb', line 102

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/ae_page_objects/core/rake_router.rb', line 106

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

#hashObject



110
111
112
# File 'lib/ae_page_objects/core/rake_router.rb', line 110

def hash
  name.hash
end

#optional?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/ae_page_objects/core/rake_router.rb', line 98

def optional?
  optional
end

#replace_param_in_url(url) ⇒ Object



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

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

#substitute(url, values) ⇒ Object



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

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