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.
4 5 6 |
# File 'lib/rulp/rulp_bounds.rb', line 4 def const @const end |
Instance Method Details
#<(val) ⇒ Object
35 36 37 |
# File 'lib/rulp/rulp_bounds.rb', line 35 def <(val) relative_constraint("<", val) end |
#<=(val) ⇒ Object
39 40 41 |
# File 'lib/rulp/rulp_bounds.rb', line 39 def <=(val) relative_constraint("<", val, true) end |
#==(val) ⇒ Object
43 44 45 |
# File 'lib/rulp/rulp_bounds.rb', line 43 def ==(val) self.const = val end |
#>(val) ⇒ Object
27 28 29 |
# File 'lib/rulp/rulp_bounds.rb', line 27 def >(val) relative_constraint(">", val) end |
#>=(val) ⇒ Object
31 32 33 |
# File 'lib/rulp/rulp_bounds.rb', line 31 def >=(val) relative_constraint(">", val, true) end |
#bounds ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rulp/rulp_bounds.rb', line 52 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
47 48 49 50 |
# File 'lib/rulp/rulp_bounds.rb', line 47 def coerce(something) @@coerced = true return self, something end |
#coerced? ⇒ Boolean
21 22 23 24 25 |
# File 'lib/rulp/rulp_bounds.rb', line 21 def coerced? was_coerced = @@coerced rescue nil @@coerced = false return was_coerced end |
#nocoerce ⇒ Object
17 18 19 |
# File 'lib/rulp/rulp_bounds.rb', line 17 def nocoerce @@coerced = false end |
#relative_constraint(direction, value, equality = false) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/rulp/rulp_bounds.rb', line 9 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 |