Class: Mustermann::Flask::Converter
- Inherits:
-
Object
- Object
- Mustermann::Flask::Converter
- Defined in:
- lib/mustermann/flask.rb
Overview
A class for easy creating of converters.
Instance Attribute Summary collapse
-
#constraint ⇒ Object
Constraint on the format used for the capture.
-
#convert ⇒ Object
Callback Should be a Proc.
Instance Method Summary collapse
-
#between(min, max) ⇒ Object
Makes sure a given value falls inbetween a min and a max.
Instance Attribute Details
#constraint ⇒ Object
Constraint on the format used for the capture. Should be a regexp (or a string corresponding to a regexp)
45 46 47 |
# File 'lib/mustermann/flask.rb', line 45 def constraint @constraint end |
#convert ⇒ Object
Callback Should be a Proc.
50 51 52 |
# File 'lib/mustermann/flask.rb', line 50 def convert @convert end |
Instance Method Details
#between(min, max) ⇒ Object
Makes sure a given value falls inbetween a min and a max. Uses the passed block to convert the value from a string to whatever format you’d expect.
87 88 89 90 91 92 93 94 |
# File 'lib/mustermann/flask.rb', line 87 def between(min, max) self.convert = proc do |input| value = yield(input) value = yield(min) if min and value < yield(min) value = yield(max) if max and value > yield(max) value end end |