Class: Phonelib::Errors

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/phonelib/errors.rb

Overview

Read-only collection of phone validation errors.

Instance Method Summary collapse

Constructor Details

#initialize(errors = []) ⇒ Errors

Returns a new instance of Errors.



8
9
10
11
# File 'lib/phonelib/errors.rb', line 8

def initialize(errors = [])
  @errors = errors.dup.freeze
  freeze
end

Instance Method Details

#detailsObject



29
30
31
# File 'lib/phonelib/errors.rb', line 29

def details
  @errors.map { |error| { error: error.code }.merge(error.details).freeze }.freeze
end

#each(&block) ⇒ Object



13
14
15
# File 'lib/phonelib/errors.rb', line 13

def each(&block)
  @errors.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/phonelib/errors.rb', line 17

def empty?
  @errors.empty?
end

#firstObject



25
26
27
# File 'lib/phonelib/errors.rb', line 25

def first
  @errors.first
end

#full_messages(options = {}) ⇒ Object



38
39
40
# File 'lib/phonelib/errors.rb', line 38

def full_messages(options = {})
  messages(options)
end

#messages(options = {}) ⇒ Object



33
34
35
36
# File 'lib/phonelib/errors.rb', line 33

def messages(options = {})
  translator = options.is_a?(Hash) ? options[:translator] : options
  @errors.map { |error| error.message(translator) }.freeze
end

#sizeObject



21
22
23
# File 'lib/phonelib/errors.rb', line 21

def size
  @errors.size
end