Class: FriendlyRoutes::Params::HashParams

Inherits:
Base
  • Object
show all
Defined in:
lib/friendly_routes/params/hash_params.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#name, #type

Instance Method Summary collapse

Methods inherited from Base

#optional?

Constructor Details

#initialize(name, hash, optional: true) ⇒ HashParams

Returns a new instance of HashParams.



8
9
10
11
12
# File 'lib/friendly_routes/params/hash_params.rb', line 8

def initialize(name, hash, optional: true)
  super(:collection, name, optional)
  @hash = hash
  check_params
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



6
7
8
# File 'lib/friendly_routes/params/hash_params.rb', line 6

def hash
  @hash
end

Instance Method Details

#constraintsObject



14
15
16
# File 'lib/friendly_routes/params/hash_params.rb', line 14

def constraints
  Regexp.new @hash.keys.join('|')
end

#parse(value) ⇒ Object



18
19
20
# File 'lib/friendly_routes/params/hash_params.rb', line 18

def parse(value)
  @hash[value]
end