Class: Pripara::Base

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

Direct Known Subclasses

Idol, Song

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Base

Returns a new instance of Base.



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

def initialize(attributes)
  @attributes = attributes.map { |k, v| [k.to_sym, v] }.to_h
end

Class Method Details

.allObject



12
13
14
# File 'lib/ruripara/base.rb', line 12

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

.find_by(attributes) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
# File 'lib/ruripara/base.rb', line 16

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)


7
8
9
# File 'lib/ruripara/base.rb', line 7

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