class ProcessAffirmationEvaluator

Attributes

args[RW]
attribute[RW]
object[RW]

Public Class Methods

new(object, attribute, args) click to toggle source
# File lib/daily_affirmation/process_affirmation_evaluator.rb, line 2
def initialize(object, attribute, args)
  self.object = object
  self.attribute = attribute
  self.args = args
end

Public Instance Methods

process?() click to toggle source
# File lib/daily_affirmation/process_affirmation_evaluator.rb, line 8
def process?
  if_statement_passes? && process_non_nil_value? && process_non_blank_value?
end

Private Instance Methods

allow_blank_values?() click to toggle source
# File lib/daily_affirmation/process_affirmation_evaluator.rb, line 28
def allow_blank_values?
  args.include?(:allow_blank)
end
allow_nil_values?() click to toggle source
# File lib/daily_affirmation/process_affirmation_evaluator.rb, line 49
def allow_nil_values?
  args.include?(:allow_nil)
end
blank?(val) click to toggle source
# File lib/daily_affirmation/process_affirmation_evaluator.rb, line 36
def blank?(val)
  case val
  when String
    val !~ /[^[:space:]]/
  else
    val.respond_to?(:empty?) ? val.empty? : !val
  end
end
if_statement_passes?() click to toggle source
# File lib/daily_affirmation/process_affirmation_evaluator.rb, line 16
def if_statement_passes?
  if args.include?(:if)
    instance_eval(&args[:if])
  else
    true
  end
end
object_is_blank?() click to toggle source
# File lib/daily_affirmation/process_affirmation_evaluator.rb, line 32
def object_is_blank?
  blank?(object.send(attribute))
end
object_is_nil?() click to toggle source
# File lib/daily_affirmation/process_affirmation_evaluator.rb, line 45
def object_is_nil?
  object.send(attribute).nil?
end
process_non_blank_value?() click to toggle source
# File lib/daily_affirmation/process_affirmation_evaluator.rb, line 24
def process_non_blank_value?
  !(allow_blank_values? && object_is_blank?)
end
process_non_nil_value?() click to toggle source
# File lib/daily_affirmation/process_affirmation_evaluator.rb, line 53
def process_non_nil_value?
  !(allow_nil_values? && object_is_nil?)
end