Class: Classifieds::Seller
- Inherits:
-
Object
- Object
- Classifieds::Seller
- 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
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#phone ⇒ Object
Returns the value of attribute phone.
Class Method Summary collapse
-
.clear ⇒ Object
Empty list of created objects.
-
.find_or_create(name, location, phone) ⇒ Object
Returns the specified seller, or creates a new one if not found in @@all.
-
.find_seller(name, location, phone) ⇒ Object
Returns the specified seller from @all or nil if not found.
-
.summary_header ⇒ Object
Return the summary listing summary title row.
Instance Method Summary collapse
-
#initialize(name, location, phone) ⇒ Seller
constructor
A new instance of Seller.
-
#summary_detail ⇒ Object
Return a summary listing detail row.
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
#location ⇒ Object (readonly)
Returns the value of attribute location.
9 10 11 |
# File 'lib/classifieds/seller.rb', line 9 def location @location end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/classifieds/seller.rb', line 9 def name @name end |
#phone ⇒ Object
Returns the value of attribute phone.
8 9 10 |
# File 'lib/classifieds/seller.rb', line 8 def phone @phone end |
Class Method Details
.clear ⇒ Object
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_header ⇒ Object
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_detail ⇒ Object
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 |