Class: LHS::Problems::Base
- Inherits:
-
Object
- Object
- LHS::Problems::Base
- Includes:
- Enumerable
- Defined in:
- lib/lhs/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.
9 10 11 |
# File 'lib/lhs/problems/base.rb', line 9 def codes @codes end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
9 10 11 |
# File 'lib/lhs/problems/base.rb', line 9 def @messages end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
9 10 11 |
# File 'lib/lhs/problems/base.rb', line 9 def raw @raw end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
9 10 11 |
# File 'lib/lhs/problems/base.rb', line 9 def record @record end |
Instance Method Details
#[](attribute) ⇒ Object
33 34 35 |
# File 'lib/lhs/problems/base.rb', line 33 def [](attribute) get(attribute.to_sym) || [attribute] = [] end |
#[]=(attribute, message) ⇒ Object
37 38 39 |
# File 'lib/lhs/problems/base.rb', line 37 def []=(attribute, ) self[attribute] << (attribute, ) end |
#add(attribute, message = :invalid, options = {}) ⇒ Object
17 18 19 20 |
# File 'lib/lhs/problems/base.rb', line 17 def add(attribute, = :invalid, = {}) self[attribute] [attribute] << (attribute, , ) end |
#clear ⇒ Object
55 56 57 58 59 |
# File 'lib/lhs/problems/base.rb', line 55 def clear @raw = nil @messages.clear @codes.clear end |
#count ⇒ Object
65 66 67 |
# File 'lib/lhs/problems/base.rb', line 65 def count to_a.size end |
#each ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/lhs/problems/base.rb', line 41 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
69 70 71 |
# File 'lib/lhs/problems/base.rb', line 69 def empty? all? { |_k, v| v&.empty? && !v.is_a?(String) } end |
#get(key) ⇒ Object
22 23 24 |
# File 'lib/lhs/problems/base.rb', line 22 def get(key) [key] end |
#include?(attribute) ⇒ Boolean Also known as: has_key?, key?
11 12 13 |
# File 'lib/lhs/problems/base.rb', line 11 def include?(attribute) [attribute].present? end |
#set(key, message) ⇒ Object
26 27 28 29 |
# File 'lib/lhs/problems/base.rb', line 26 def set(key, ) return if .blank? [key] = [(key, )] end |
#size ⇒ Object
51 52 53 |
# File 'lib/lhs/problems/base.rb', line 51 def size values.flatten.size end |