Class: Shoulda::Matchers::ActiveRecord::NormalizeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/matchers/active_record/normalize_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*attributes) ⇒ NormalizeMatcher

Returns a new instance of NormalizeMatcher.



81
82
83
# File 'lib/shoulda/matchers/active_record/normalize_matcher.rb', line 81

def initialize(*attributes)
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



78
79
80
# File 'lib/shoulda/matchers/active_record/normalize_matcher.rb', line 78

def attributes
  @attributes
end

#failure_messageObject (readonly)

Returns the value of attribute failure_message.



78
79
80
# File 'lib/shoulda/matchers/active_record/normalize_matcher.rb', line 78

def failure_message
  @failure_message
end

#failure_message_when_negatedObject (readonly)

Returns the value of attribute failure_message_when_negated.



78
79
80
# File 'lib/shoulda/matchers/active_record/normalize_matcher.rb', line 78

def failure_message_when_negated
  @failure_message_when_negated
end

#from_valueObject (readonly)

Returns the value of attribute from_value.



78
79
80
# File 'lib/shoulda/matchers/active_record/normalize_matcher.rb', line 78

def from_value
  @from_value
end

#to_valueObject (readonly)

Returns the value of attribute to_value.



78
79
80
# File 'lib/shoulda/matchers/active_record/normalize_matcher.rb', line 78

def to_value
  @to_value
end

Instance Method Details

#descriptionObject



85
86
87
88
89
90
# File 'lib/shoulda/matchers/active_record/normalize_matcher.rb', line 85

def description
  %(
    normalize #{attributes.to_sentence(last_word_connector: ' and ')} from
    ‹#{from_value.inspect}› to ‹#{to_value.inspect}).squish
end

#does_not_match?(subject) ⇒ Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/shoulda/matchers/active_record/normalize_matcher.rb', line 108

def does_not_match?(subject)
  attributes.all? { |attribute| attribute_does_not_match?(subject, attribute) }
end

#from(value) ⇒ Object



92
93
94
95
96
# File 'lib/shoulda/matchers/active_record/normalize_matcher.rb', line 92

def from(value)
  @from_value = value

  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/shoulda/matchers/active_record/normalize_matcher.rb', line 104

def matches?(subject)
  attributes.all? { |attribute| attribute_matches?(subject, attribute) }
end

#to(value) ⇒ Object



98
99
100
101
102
# File 'lib/shoulda/matchers/active_record/normalize_matcher.rb', line 98

def to(value)
  @to_value = value

  self
end