Class: FriendlyRoutes::Params::BooleanParams

Inherits:
Base
  • Object
show all
Defined in:
lib/friendly_routes/params/boolean_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, options, optional: true) ⇒ BooleanParams

Returns a new instance of BooleanParams.



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

def initialize(name, options, optional: true)
  check_params(options)
  super(:boolean, name, optional)
  @true = options[:true]
  @false = options[:false]
end

Instance Attribute Details

#falseObject

Returns the value of attribute false.



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

def false
  @false
end

#trueObject

Returns the value of attribute true.



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

def true
  @true
end

Instance Method Details

#constraintsObject



15
16
17
# File 'lib/friendly_routes/params/boolean_params.rb', line 15

def constraints
  Regexp.new "#{@true}|#{@false}"
end

#parse(value) ⇒ Object



19
20
21
# File 'lib/friendly_routes/params/boolean_params.rb', line 19

def parse(value)
  value == @true
end