Class: Lego::Value::Float
- Inherits:
-
Base
- Object
- Base
- Lego::Value::Float
show all
- Defined in:
- lib/lego/value/float.rb
Instance Method Summary
collapse
Methods inherited from Base
#coerce, #initialize, #parse
Instance Method Details
#maximum ⇒ Object
17
18
19
|
# File 'lib/lego/value/float.rb', line 17
def maximum
@opts.fetch(:max, 1.0/0)
end
|
#minimum ⇒ Object
13
14
15
|
# File 'lib/lego/value/float.rb', line 13
def minimum
@opts.fetch(:min, -1.0/0)
end
|
#parsers ⇒ Object
4
5
6
7
8
9
10
11
|
# File 'lib/lego/value/float.rb', line 4
def parsers
[
->(v) { v.to_s.empty? ? Lego.none : Lego.just(v) },
->(v) { Lego.just(Float(v.to_s)) rescue Lego.fail("invalid float: '#{v}'") },
->(v) { v < minimum ? Lego.fail("less than minimum of #{minimum}: '#{v}'") : Lego.just(v) },
->(v) { v > maximum ? Lego.fail("more than maximum of #{maximum}: '#{v}'") : Lego.just(v) },
]
end
|