Class: DHS::Problems::Base
- Inherits:
-
Object
- Object
- DHS::Problems::Base
- Includes:
- Enumerable
- Defined in:
- lib/dhs/problems/base.rb
Instance Attribute Summary collapse
-
#codes ⇒ Object
readonly
Returns the value of attribute codes.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
- #[](attribute) ⇒ Object
- #[]=(attribute, message) ⇒ Object
- #add(attribute, message = :invalid, options = {}) ⇒ Object
- #clear ⇒ Object
- #count ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #get(key) ⇒ Object
- #include?(attribute) ⇒ Boolean (also: #has_key?, #key?)
- #set(key, message) ⇒ Object
- #size ⇒ Object
Instance Attribute Details
#codes ⇒ Object (readonly)
Returns the value of attribute codes.
11 12 13 |
# File 'lib/dhs/problems/base.rb', line 11 def codes @codes end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
11 12 13 |
# File 'lib/dhs/problems/base.rb', line 11 def @messages end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
11 12 13 |
# File 'lib/dhs/problems/base.rb', line 11 def raw @raw end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
11 12 13 |
# File 'lib/dhs/problems/base.rb', line 11 def record @record end |
Instance Method Details
#[](attribute) ⇒ Object
35 36 37 |
# File 'lib/dhs/problems/base.rb', line 35 def [](attribute) get(attribute.to_sym) || [attribute] = [] end |
#[]=(attribute, message) ⇒ Object
39 40 41 |
# File 'lib/dhs/problems/base.rb', line 39 def []=(attribute, ) self[attribute] << (attribute, ) end |
#add(attribute, message = :invalid, options = {}) ⇒ Object
19 20 21 22 |
# File 'lib/dhs/problems/base.rb', line 19 def add(attribute, = :invalid, = {}) self[attribute] [attribute] << (attribute, , ) end |
#clear ⇒ Object
57 58 59 60 61 |
# File 'lib/dhs/problems/base.rb', line 57 def clear @raw = nil @messages.clear @codes.clear end |
#count ⇒ Object
67 68 69 |
# File 'lib/dhs/problems/base.rb', line 67 def count to_a.size end |
#each ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/dhs/problems/base.rb', line 43 def each if .is_a?(Hash) .each_key do |attribute| self[attribute].each { || yield attribute, } end elsif .is_a?(Array) .each { || yield } end end |
#empty? ⇒ Boolean
71 72 73 |
# File 'lib/dhs/problems/base.rb', line 71 def empty? all? { |_k, v| v&.empty? && !v.is_a?(String) } end |
#get(key) ⇒ Object
24 25 26 |
# File 'lib/dhs/problems/base.rb', line 24 def get(key) [key] end |
#include?(attribute) ⇒ Boolean Also known as: has_key?, key?
13 14 15 |
# File 'lib/dhs/problems/base.rb', line 13 def include?(attribute) [attribute].present? end |
#set(key, message) ⇒ Object
28 29 30 31 |
# File 'lib/dhs/problems/base.rb', line 28 def set(key, ) return if .blank? [key] = [(key, )] end |
#size ⇒ Object
53 54 55 |
# File 'lib/dhs/problems/base.rb', line 53 def size values.flatten.size end |