Class: Classifieds::Seller

Inherits:
Object
  • Object
show all
Defined in:
lib/classifieds/seller.rb

Overview

describes the entity that is selling the .Item in a .Listing

Constant Summary collapse

SUMMARY_COL_FORMATS =

A seller is uniquely identified by name + location + phone

[[28,'l'], [32,'l']]
@@all_sellers =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, location, phone) ⇒ Seller

Returns a new instance of Seller.



13
14
15
16
17
18
# File 'lib/classifieds/seller.rb', line 13

def initialize(name, location, phone)
  @name = name
  @location = location
  @phone = phone
  Classifieds::Seller.all << self
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



9
10
11
# File 'lib/classifieds/seller.rb', line 9

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/classifieds/seller.rb', line 9

def name
  @name
end

#phoneObject

Returns the value of attribute phone.



8
9
10
# File 'lib/classifieds/seller.rb', line 8

def phone
  @phone
end

Class Method Details

.clearObject

Empty list of created objects



21
22
23
# File 'lib/classifieds/seller.rb', line 21

def self.clear
  all.clear
end

.find_or_create(name, location, phone) ⇒ Object

Returns the specified seller, or creates a new one if not found in @@all



26
27
28
# File 'lib/classifieds/seller.rb', line 26

def self.find_or_create(name, location, phone)
  (seller = find_seller(name, location, phone)) != nil ? seller : new(name, location, phone)
end

.find_seller(name, location, phone) ⇒ Object

Returns the specified seller from @all or nil if not found



31
32
33
# File 'lib/classifieds/seller.rb', line 31

def self.find_seller(name, location, phone)
  all.find { |seller| seller.name == name && seller.location == location && seller.phone == phone }
end

.summary_headerObject

Return the summary listing summary title row



41
42
43
# File 'lib/classifieds/seller.rb', line 41

def self.summary_header
  Classifieds::Listing.format_cols(['Seller', 'Location'], SUMMARY_COL_FORMATS)
end

Instance Method Details

#summary_detailObject

Return a summary listing detail row



36
37
38
# File 'lib/classifieds/seller.rb', line 36

def summary_detail
  Classifieds::Listing.format_cols([@name, @location], SUMMARY_COL_FORMATS)
end