Class: Phonelib::Errors
- Inherits:
-
Object
- Object
- Phonelib::Errors
- Includes:
- Enumerable
- Defined in:
- lib/phonelib/errors.rb
Overview
Read-only collection of phone validation errors.
Instance Method Summary collapse
- #details ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #first ⇒ Object
- #full_messages(options = {}) ⇒ Object
-
#initialize(errors = []) ⇒ Errors
constructor
A new instance of Errors.
- #messages(options = {}) ⇒ Object
- #size ⇒ Object
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
#details ⇒ Object
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
17 18 19 |
# File 'lib/phonelib/errors.rb', line 17 def empty? @errors.empty? end |
#first ⇒ Object
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 ( = {}) () end |
#messages(options = {}) ⇒ Object
33 34 35 36 |
# File 'lib/phonelib/errors.rb', line 33 def ( = {}) translator = .is_a?(Hash) ? [:translator] : @errors.map { |error| error.(translator) }.freeze end |
#size ⇒ Object
21 22 23 |
# File 'lib/phonelib/errors.rb', line 21 def size @errors.size end |