Class: Aequitas::Rule::SkipCondition

Inherits:
Object
  • Object
show all
Extended by:
ValueObject
Defined in:
lib/aequitas/rule/skip_condition.rb

Instance Attribute Summary collapse

Attributes included from ValueObject

#equalizer

Instance Method Summary collapse

Methods included from ValueObject

equalize_on

Constructor Details

#initialize(options = {}) ⇒ SkipCondition

Returns a new instance of SkipCondition.



16
17
18
19
# File 'lib/aequitas/rule/skip_condition.rb', line 16

def initialize(options = {})
  @allow_nil   = !!options[:allow_nil]   if options.include?(:allow_nil)
  @allow_blank = !!options[:allow_blank] if options.include?(:allow_blank)
end

Instance Attribute Details

#allow_blankObject (readonly)

Returns the value of attribute allow_blank.



14
15
16
# File 'lib/aequitas/rule/skip_condition.rb', line 14

def allow_blank
  @allow_blank
end

#allow_nilObject (readonly)

Returns the value of attribute allow_nil.



13
14
15
# File 'lib/aequitas/rule/skip_condition.rb', line 13

def allow_nil
  @allow_nil
end

Instance Method Details

#allow_blank!self

Set the receiver to allow blank values

Returns:

  • (self)


63
64
65
66
# File 'lib/aequitas/rule/skip_condition.rb', line 63

def allow_blank!
  @allow_blank = true
  self
end

#allow_blank?Boolean

Inquire whether the receiver is configured to allow blank values

Returns:

  • (Boolean)


48
49
50
# File 'lib/aequitas/rule/skip_condition.rb', line 48

def allow_blank?
  @allow_blank.nil? ? false : @allow_blank
end

#allow_nil!self

Set the receiver to allow nil values

Returns:

  • (self)


55
56
57
58
# File 'lib/aequitas/rule/skip_condition.rb', line 55

def allow_nil!
  @allow_nil = true
  self
end

#allow_nil?Boolean

Inquire whether the receiver is configured to allow nil values

Returns:

  • (Boolean)


41
42
43
# File 'lib/aequitas/rule/skip_condition.rb', line 41

def allow_nil?
  @allow_nil.nil? ? false : @allow_nil
end

#default_to_allowing_blank!self

Set the receiver to allow blank values

if a value has not already been set

Returns:

  • (self)


97
98
99
100
# File 'lib/aequitas/rule/skip_condition.rb', line 97

def default_to_allowing_blank!
  allow_blank! if allow_blank.nil?
  self
end

#default_to_allowing_nil!self

Set the receiver to allow nil values

if a value has not already been set

Returns:

  • (self)


88
89
90
91
# File 'lib/aequitas/rule/skip_condition.rb', line 88

def default_to_allowing_nil!
  allow_nil! if allow_nil.nil?
  self
end

#reject_blank!self

Set the receiver to reject blank values

Returns:

  • (self)


79
80
81
82
# File 'lib/aequitas/rule/skip_condition.rb', line 79

def reject_blank!
  @allow_blank = false
  self
end

#reject_nil!self

Set the receiver to reject nil values

Returns:

  • (self)


71
72
73
74
# File 'lib/aequitas/rule/skip_condition.rb', line 71

def reject_nil!
  @allow_nil = false
  self
end

#skip?(value) ⇒ Boolean

Test a value to determine if it should be skipped,

according to the receiver's configuration

Parameters:

  • value (#nil?)

    the value to be tested

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
# File 'lib/aequitas/rule/skip_condition.rb', line 28

def skip?(value)
  if value.nil?
    @allow_nil.nil? ? allow_blank? : allow_nil?
  elsif Aequitas.blank?(value)
    allow_blank?
  else
    false
  end
end