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)
47 48 49 |
# File 'lib/mustermann/flask.rb', line 47 def constraint @constraint end |
#convert ⇒ Object
Callback Should be a Proc.
52 53 54 |
# File 'lib/mustermann/flask.rb', line 52 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.
89 90 91 92 93 94 95 96 |
# File 'lib/mustermann/flask.rb', line 89 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 |