Class: RichterCatalogue::Painting

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

Constant Summary collapse

@@all =
[]
@@names_all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes_hash) ⇒ Painting

Returns a new instance of Painting.



8
9
10
11
# File 'lib/richter_catalogue/painting.rb', line 8

def initialize(attributes_hash)
  attributes_hash.each {|key, value| self.send("#{key}=", value)}
  @@all << self
end

Instance Attribute Details

#artistObject

Returns the value of attribute artist.



3
4
5
# File 'lib/richter_catalogue/painting.rb', line 3

def artist
  @artist
end

#mediumObject

Returns the value of attribute medium.



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

def medium
  @medium
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#painting_urlObject

Returns the value of attribute painting_url.



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

def painting_url
  @painting_url
end

#priceObject

Returns the value of attribute price.



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

def price
  @price
end

#sizeObject

Returns the value of attribute size.



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

def size
  @size
end

#subjectObject

Returns the value of attribute subject.



3
4
5
# File 'lib/richter_catalogue/painting.rb', line 3

def subject
  @subject
end

#yearObject

Returns the value of attribute year.



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

def year
  @year
end

Class Method Details

.allObject



28
29
30
# File 'lib/richter_catalogue/painting.rb', line 28

def self.all
  @@all
end

.create_from_subject(paintings_array, subject = nil) ⇒ Object



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

def self.create_from_subject(paintings_array, subject = nil)
  paintings_array.each do |attributes_hash|
    new_painting = RichterCatalogue::Painting.new(attributes_hash)
    new_painting.subject = subject
  end
end

.display(painting) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/richter_catalogue/painting.rb', line 51

def self.display(painting)

  puts "  name: #{painting.name}"
  puts "  year: #{painting.year.name}"
  puts "  size: #{painting.size}"
  puts "  medium: #{painting.medium}"

  if !(painting.price == "")
    puts "  price: #{painting.price}"
  end
  puts "------------------------"
end

.display_name(painting) ⇒ Object



47
48
49
# File 'lib/richter_catalogue/painting.rb', line 47

def self.display_name(painting)
  puts "- #{painting.name}"
end

.find_by_name(name) ⇒ Object



68
69
70
# File 'lib/richter_catalogue/painting.rb', line 68

def self.find_by_name(name)
  self.all.select{|painting| painting.name == name}
end

.namesObject



64
65
66
# File 'lib/richter_catalogue/painting.rb', line 64

def self.names
  RichterCatalogue::Painting.all.collect {|painting| painting.name}.uniq
end

Instance Method Details

#add_attributes(attributes_hash) ⇒ Object



21
22
23
24
25
26
# File 'lib/richter_catalogue/painting.rb', line 21

def add_attributes(attributes_hash)
  attributes_hash.each do |key, value|
      self.send("#{key}=", value)
  end
  self
end