Class: Tsubaki::Shoulda::Matchers::ValidateCorporateNumberOfMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/tsubaki/matchers/validate_corporate_number_of_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(attribute_name) ⇒ ValidateCorporateNumberOfMatcher

Returns a new instance of ValidateCorporateNumberOfMatcher.



17
18
19
20
21
22
23
24
25
# File 'lib/tsubaki/matchers/validate_corporate_number_of_matcher.rb', line 17

def initialize(attribute_name)
  @attribute_name = attribute_name
  @options = {}
  @options[:strict] = nil
  @options[:divider] = nil
  @options[:allow_blank] = nil
  @failure_messages = []
  self
end

Instance Method Details

#allow_blank(allow_blank = true) ⇒ Object



56
57
58
59
# File 'lib/tsubaki/matchers/validate_corporate_number_of_matcher.rb', line 56

def allow_blank(allow_blank = true)
  @options[:allow_blank] = allow_blank
  self
end

#descriptionObject



37
38
39
40
41
42
43
44
# File 'lib/tsubaki/matchers/validate_corporate_number_of_matcher.rb', line 37

def description
  result = 'ensure corporate number format'
  result << " for #{@attribute_name}"
  result << ' with strict mode' if @options[:strict].present?
  result << " with divider '#{@options[:divider]}'" if @options[:divider].present?
  result << ' and allow blank' if @options[:allow_blank].present?
  result
end

#failure_messageObject



33
34
35
# File 'lib/tsubaki/matchers/validate_corporate_number_of_matcher.rb', line 33

def failure_message
  @failure_messages.join("\n")
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/tsubaki/matchers/validate_corporate_number_of_matcher.rb', line 27

def matches?(subject)
  @subject = subject
  @subject = @subject.new if @subject.class == Class
  (error_when_not_valid + no_error_when_valid).all?
end

#strict(strict = true) ⇒ Object



46
47
48
49
# File 'lib/tsubaki/matchers/validate_corporate_number_of_matcher.rb', line 46

def strict(strict = true)
  @options[:strict] = strict
  self
end

#with_divider(divider) ⇒ Object



51
52
53
54
# File 'lib/tsubaki/matchers/validate_corporate_number_of_matcher.rb', line 51

def with_divider(divider)
  @options[:divider] = divider
  self
end