Class: Inquirex::Rules::LessThan
- Defined in:
- lib/inquirex/rules/less_than.rb
Overview
Rule: the answer for the given field (coerced to integer) is less than the threshold.
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(answers) ⇒ Object
-
#initialize(field, value) ⇒ LessThan
constructor
A new instance of LessThan.
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(field, value) ⇒ LessThan
Returns a new instance of LessThan.
9 10 11 12 13 14 |
# File 'lib/inquirex/rules/less_than.rb', line 9 def initialize(field, value) super() @field = field.to_sym @value = value freeze end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
7 8 9 |
# File 'lib/inquirex/rules/less_than.rb', line 7 def field @field end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/inquirex/rules/less_than.rb', line 7 def value @value end |
Class Method Details
.from_h(hash) ⇒ Object
28 29 30 31 32 |
# File 'lib/inquirex/rules/less_than.rb', line 28 def self.from_h(hash) field = hash["field"] || hash[:field] value = (hash["value"] || hash[:value]).to_i new(field, value) end |
Instance Method Details
#evaluate(answers) ⇒ Object
16 17 18 |
# File 'lib/inquirex/rules/less_than.rb', line 16 def evaluate(answers) answers[@field].to_i < @value end |
#to_h ⇒ Object
20 21 22 |
# File 'lib/inquirex/rules/less_than.rb', line 20 def to_h { "op" => "less_than", "field" => @field.to_s, "value" => @value } end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/inquirex/rules/less_than.rb', line 24 def to_s "#{@field} < #{@value}" end |