Class: Lego::Value::Float

Inherits:
Base
  • Object
show all
Defined in:
lib/lego/value/float.rb

Instance Method Summary collapse

Methods inherited from Base

#coerce, #initialize, #parse

Constructor Details

This class inherits a constructor from Lego::Value::Base

Instance Method Details

#maximumObject



17
18
19
# File 'lib/lego/value/float.rb', line 17

def maximum
  @opts.fetch(:max, 1.0/0)
end

#minimumObject



13
14
15
# File 'lib/lego/value/float.rb', line 13

def minimum
  @opts.fetch(:min, -1.0/0)
end

#parsersObject



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