Module: Rulp::Bounds
- Included in:
- LV
- Defined in:
- lib/rulp/rulp_bounds.rb
Constant Summary collapse
- DIRS =
{">" => {value: "gt=", equality: "gte="}, "<" => {value: "lt=", equality: "lte="}}
- DIRS_REVERSED =
{">" => DIRS["<"], "<" => DIRS[">"]}
Instance Attribute Summary collapse
-
#const ⇒ Object
Returns the value of attribute const.
Instance Method Summary collapse
- #<(val) ⇒ Object
- #<=(val) ⇒ Object
- #==(val) ⇒ Object
- #>(val) ⇒ Object
- #>=(val) ⇒ Object
- #bounds ⇒ Object
- #coerce(something) ⇒ Object
- #coerced? ⇒ Boolean
- #nocoerce ⇒ Object
- #relative_constraint(direction, value, equality = false) ⇒ Object
Instance Attribute Details
#const ⇒ Object
Returns the value of attribute const.
6 7 8 |
# File 'lib/rulp/rulp_bounds.rb', line 6 def const @const end |
Instance Method Details
#<(val) ⇒ Object
37 38 39 |
# File 'lib/rulp/rulp_bounds.rb', line 37 def <(val) relative_constraint("<", val) end |
#<=(val) ⇒ Object
41 42 43 |
# File 'lib/rulp/rulp_bounds.rb', line 41 def <=(val) relative_constraint("<", val, true) end |
#==(val) ⇒ Object
45 46 47 |
# File 'lib/rulp/rulp_bounds.rb', line 45 def ==(val) self.const = val end |
#>(val) ⇒ Object
29 30 31 |
# File 'lib/rulp/rulp_bounds.rb', line 29 def >(val) relative_constraint(">", val) end |
#>=(val) ⇒ Object
33 34 35 |
# File 'lib/rulp/rulp_bounds.rb', line 33 def >=(val) relative_constraint(">", val, true) end |
#bounds ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rulp/rulp_bounds.rb', line 54 def bounds return nil if !(self.gt || self.lt || self.const) return "#{self.name} = #{self.const}" if self.const [ self.gt, self.gt ? "<=" : nil, self.to_s, self.lt ? "<=" : nil, self.lt ].compact.join(" ") end |
#coerce(something) ⇒ Object
49 50 51 52 |
# File 'lib/rulp/rulp_bounds.rb', line 49 def coerce(something) @@coerced = true return self, something end |
#coerced? ⇒ Boolean
23 24 25 26 27 |
# File 'lib/rulp/rulp_bounds.rb', line 23 def coerced? was_coerced = @@coerced rescue nil @@coerced = false return was_coerced end |
#nocoerce ⇒ Object
19 20 21 |
# File 'lib/rulp/rulp_bounds.rb', line 19 def nocoerce @@coerced = false end |
#relative_constraint(direction, value, equality = false) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/rulp/rulp_bounds.rb', line 11 def relative_constraint direction, value, equality=false direction = coerced? ? DIRS_REVERSED[direction] : DIRS[direction] self.const = false self.send(direction[:value], value) self.send(direction[:equality], equality) return self end |