Class: SimpleParams::ValidationMatchers::FormatMatcher

Inherits:
ValidationMatcher
  • Object
show all
Defined in:
lib/simple_params/validation_matchers/format_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ FormatMatcher

Returns a new instance of FormatMatcher.



10
11
12
13
# File 'lib/simple_params/validation_matchers/format_matcher.rb', line 10

def initialize(attribute)
  super(attribute)
  @unformatted_value = nil
end

Instance Attribute Details

#attributeObject

Returns the value of attribute attribute.



8
9
10
# File 'lib/simple_params/validation_matchers/format_matcher.rb', line 8

def attribute
  @attribute
end

#default_valueObject

Returns the value of attribute default_value.



8
9
10
# File 'lib/simple_params/validation_matchers/format_matcher.rb', line 8

def default_value
  @default_value
end

Instance Method Details

#descriptionObject



31
32
33
# File 'lib/simple_params/validation_matchers/format_matcher.rb', line 31

def description
  "Expect #{@attribute} with_value #{@unformatted_value} to format into #{@expected_value}"
end

#failure_message_for_shouldObject



35
36
37
# File 'lib/simple_params/validation_matchers/format_matcher.rb', line 35

def failure_message_for_should
  "Expect #{@attribute} with_value #{@unformatted_value} to format into #{@expected_value}"
end

#failure_message_for_should_notObject



39
40
41
# File 'lib/simple_params/validation_matchers/format_matcher.rb', line 39

def failure_message_for_should_not
  "Expected #{@attribute} with_value #{@unformatted_value} to not format into #{@expected_value}"
end

#into(value) ⇒ Object



20
21
22
23
# File 'lib/simple_params/validation_matchers/format_matcher.rb', line 20

def into(value)
  @expected_value = value
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/simple_params/validation_matchers/format_matcher.rb', line 25

def matches?(subject)
  super(subject)
  @subject.send("#{@attribute}=", @unformatted_value)
  @subject.send(attribute) == @expected_value
end

#with_value(value) ⇒ Object



15
16
17
18
# File 'lib/simple_params/validation_matchers/format_matcher.rb', line 15

def with_value(value)
  @unformatted_value = value
  self
end