Class: VanillaValidator::Rules::OtherRule

Inherits:
Object
  • Object
show all
Defined in:
lib/vanilla_validator/rules/other_rule.rb

Constant Summary collapse

DEFAULT_RULE_NAME =
'eq'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, term_array) ⇒ OtherRule

Returns a new instance of OtherRule.



8
9
10
11
12
13
14
# File 'lib/vanilla_validator/rules/other_rule.rb', line 8

def initialize(input, term_array)
  self.attribute = term_array[0]
  self.name = term_array.length == 2 ? DEFAULT_RULE_NAME : term_array[1]
  self.parameters = self.normalize(term_array[name == DEFAULT_RULE_NAME ? 1..-1 : 2..-1])
  self.value = ValueExtractor.get(input, attribute)
  self.klass = self.initialize_rule(name, value, parameters)
end

Instance Attribute Details

#attributeObject

Returns the value of attribute attribute.



4
5
6
# File 'lib/vanilla_validator/rules/other_rule.rb', line 4

def attribute
  @attribute
end

#klassObject

Returns the value of attribute klass.



4
5
6
# File 'lib/vanilla_validator/rules/other_rule.rb', line 4

def klass
  @klass
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/vanilla_validator/rules/other_rule.rb', line 4

def name
  @name
end

#parametersObject

Returns the value of attribute parameters.



4
5
6
# File 'lib/vanilla_validator/rules/other_rule.rb', line 4

def parameters
  @parameters
end

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/vanilla_validator/rules/other_rule.rb', line 4

def value
  @value
end

Class Method Details

.call(input, term_array) ⇒ Object



16
17
18
# File 'lib/vanilla_validator/rules/other_rule.rb', line 16

def self.call(input, term_array)
  self.new(input, term_array)
end