Class: FlowEngine::Rules::NotEmpty
- Defined in:
- lib/flowengine/rules/not_empty.rb
Overview
Rule: the answer for the given field is present and not empty (nil or empty? => false).
Instance Attribute Summary collapse
-
#field ⇒ Symbol
readonly
answer key.
Instance Method Summary collapse
-
#evaluate(answers) ⇒ Boolean
False if nil or empty, true otherwise.
-
#initialize(field) ⇒ NotEmpty
constructor
A new instance of NotEmpty.
-
#to_s ⇒ String
E.g.
Constructor Details
#initialize(field) ⇒ NotEmpty
Returns a new instance of NotEmpty.
12 13 14 15 16 |
# File 'lib/flowengine/rules/not_empty.rb', line 12 def initialize(field) super() @field = field freeze end |
Instance Attribute Details
#field ⇒ Symbol (readonly)
answer key
8 9 10 |
# File 'lib/flowengine/rules/not_empty.rb', line 8 def field @field end |
Instance Method Details
#evaluate(answers) ⇒ Boolean
Returns false if nil or empty, true otherwise.
20 21 22 23 24 25 26 |
# File 'lib/flowengine/rules/not_empty.rb', line 20 def evaluate(answers) val = answers[field] return false if val.nil? return false if val.respond_to?(:empty?) && val.empty? true end |
#to_s ⇒ String
Returns e.g. "name is not empty".
29 30 31 |
# File 'lib/flowengine/rules/not_empty.rb', line 29 def to_s "#{field} is not empty" end |