Class: Pripara::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ruripara/base.rb

Direct Known Subclasses

Brand, Charm, Idol, Song

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#attributesObject (readonly)

Returns the value of attribute attributes.



3
4
5
# File 'lib/ruripara/base.rb', line 3

def attributes
  @attributes
end

Class Method Details

.allObject



14
15
16
# File 'lib/ruripara/base.rb', line 14

def all
  config.map { |attributes| new(attributes) }
end

.find_by(attributes) ⇒ Object

Raises:

  • (ArgumentError)


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

Returns:

  • (Boolean)


9
10
11
# File 'lib/ruripara/base.rb', line 9

def match?(attrs)
  attrs.all? { |key, value| @attributes[key.to_sym] == value }
end