Class: RichterCatalogue::Subject

Inherits:
Object
  • Object
show all
Defined in:
lib/richter_catalogue/subject.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSubject

Returns a new instance of Subject.



5
6
7
8
# File 'lib/richter_catalogue/subject.rb', line 5

def initialize
  @@all << self
  @paintings = []
end

Instance Attribute Details

#artistsObject

Returns the value of attribute artists.



2
3
4
# File 'lib/richter_catalogue/subject.rb', line 2

def artists
  @artists
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/richter_catalogue/subject.rb', line 2

def name
  @name
end

#paintingsObject

Returns the value of attribute paintings.



2
3
4
# File 'lib/richter_catalogue/subject.rb', line 2

def paintings
  @paintings
end

#subject_urlObject

Returns the value of attribute subject_url.



2
3
4
# File 'lib/richter_catalogue/subject.rb', line 2

def subject_url
  @subject_url
end

Class Method Details

.allObject



10
11
12
# File 'lib/richter_catalogue/subject.rb', line 10

def self.all
  @@all
end

.create_from_subjects(subjects_array) ⇒ Object



14
15
16
17
18
19
# File 'lib/richter_catalogue/subject.rb', line 14

def self.create_from_subjects(subjects_array)
  subjects_array.each do |subject_hash|
    new_subject = RichterCatalogue::Subject.new
    subject_hash.each {|key, value| new_subject.send("#{key}=", value)}
  end
end

.find_by_name(name) ⇒ Object



30
31
32
# File 'lib/richter_catalogue/subject.rb', line 30

def self.find_by_name(name)
  self.all.detect{|subject| subject.name == name}
end

Instance Method Details

#add_painting(painting) ⇒ Object



25
26
27
28
# File 'lib/richter_catalogue/subject.rb', line 25

def add_painting(painting)
  painting.artist = self unless painting.artist == self
  @paintings << painting unless @paintings.include?(painting)
end