Class: HashyValueValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/hashy_validator/hashy_value_validator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, options = {}) ⇒ HashyValueValidator

Returns a new instance of HashyValueValidator.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/hashy_validator/hashy_value_validator.rb', line 4

def initialize(value, options = {})
  @value = value.blank? ? [] : value
  @valid = true
  @reason = nil
  @validations = {}
  @unique_attrs = {}
  @boolean_attrs = []

  check_parse_value
  define_validations(options)
end

Instance Attribute Details

#boolean_attrsObject (readonly)

Returns the value of attribute boolean_attrs.



20
21
22
# File 'lib/hashy_validator/hashy_value_validator.rb', line 20

def boolean_attrs
  @boolean_attrs
end

#reasonObject (readonly)

Returns the value of attribute reason.



20
21
22
# File 'lib/hashy_validator/hashy_value_validator.rb', line 20

def reason
  @reason
end

#unique_attrsObject (readonly)

Returns the value of attribute unique_attrs.



20
21
22
# File 'lib/hashy_validator/hashy_value_validator.rb', line 20

def unique_attrs
  @unique_attrs
end

#validationsObject (readonly)

Returns the value of attribute validations.



20
21
22
# File 'lib/hashy_validator/hashy_value_validator.rb', line 20

def validations
  @validations
end

#valueObject (readonly)

Returns the value of attribute value.



20
21
22
# File 'lib/hashy_validator/hashy_value_validator.rb', line 20

def value
  @value
end

Class Method Details

.get_boolean_value(value) ⇒ Object



22
23
24
25
26
27
# File 'lib/hashy_validator/hashy_value_validator.rb', line 22

def self.get_boolean_value(value)
  return true if [true, "true"].include?(value)
  return false if [false, "false"].include?(value)

  nil
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/hashy_validator/hashy_value_validator.rb', line 16

def valid?
  @valid
end