Class: Amaranth::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/amaranth/collection.rb

Direct Known Subclasses

Project, Video

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Collection

Returns a new instance of Collection.



23
24
25
# File 'lib/amaranth/collection.rb', line 23

def initialize attributes={}
  self.attributes = attributes
end

Class Method Details

.field(key) ⇒ Object



13
14
15
16
17
# File 'lib/amaranth/collection.rb', line 13

def self.field key
  @fields ||= []
  @fields << key
  attr_accessor key
end

.fieldsObject



19
20
21
# File 'lib/amaranth/collection.rb', line 19

def self.fields
  @fields
end

Instance Method Details

#==(other) ⇒ Object



33
34
35
# File 'lib/amaranth/collection.rb', line 33

def == other
  self.attributes == other.attributes
end

#attributesObject Also known as: to_h



37
38
39
40
41
# File 'lib/amaranth/collection.rb', line 37

def attributes
  self.class.fields.reduce({}) do |attrs, key|
    attrs.merge key => send(key)
  end
end

#attributes=(attributes) ⇒ Object



27
28
29
30
31
# File 'lib/amaranth/collection.rb', line 27

def attributes= attributes
  attributes.each do |key, value|
    send :"#{key}=", value
  end
end