Class: Pripara::Base
- Inherits:
-
Object
- Object
- Pripara::Base
- Defined in:
- lib/ruripara/base.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Base
constructor
A new instance of Base.
- #match?(attrs) ⇒ Boolean
Constructor Details
#initialize(attributes) ⇒ Base
Returns a new instance of Base.
5 6 7 |
# File 'lib/ruripara/base.rb', line 5 def initialize(attributes) @attributes = attributes.map { |k, v| [k.to_sym, v] }.to_h end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/ruripara/base.rb', line 3 def attributes @attributes end |
Class Method Details
.all ⇒ Object
14 15 16 |
# File 'lib/ruripara/base.rb', line 14 def all config.map { |attributes| new(attributes) } end |
.find_by(attributes) ⇒ Object
18 19 20 21 |
# File 'lib/ruripara/base.rb', line 18 def find_by(attributes) raise ArgumentError unless (attributes.keys - attr_keys).empty? all.find { |obj| obj.match?(attributes) } end |
Instance Method Details
#match?(attrs) ⇒ Boolean
9 10 11 |
# File 'lib/ruripara/base.rb', line 9 def match?(attrs) attrs.all? { |key, value| @attributes[key.to_sym] == value } end |