Class: SmartphoneFinder::Brand
- Inherits:
-
Object
- Object
- SmartphoneFinder::Brand
- Extended by:
- HelperMethods
- Includes:
- HelperMethods
- Defined in:
- lib/smartphone_finder/brand.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#devices ⇒ Object
Returns the value of attribute devices.
-
#name ⇒ Object
Returns the value of attribute name.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #add_device(device) ⇒ Object
-
#initialize(name, url) ⇒ Brand
constructor
A new instance of Brand.
- #list_devices ⇒ Object
Methods included from HelperMethods
Constructor Details
#initialize(name, url) ⇒ Brand
Returns a new instance of Brand.
8 9 10 11 12 13 14 15 |
# File 'lib/smartphone_finder/brand.rb', line 8 def initialize(name , url) @name=name @url= url @devices=[] if ! obj_exist? @@all.push(self) end end |
Instance Attribute Details
#devices ⇒ Object
Returns the value of attribute devices.
7 8 9 |
# File 'lib/smartphone_finder/brand.rb', line 7 def devices @devices end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/smartphone_finder/brand.rb', line 7 def name @name end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/smartphone_finder/brand.rb', line 7 def url @url end |
Class Method Details
.all ⇒ Object
24 25 26 |
# File 'lib/smartphone_finder/brand.rb', line 24 def self.all @@all end |
.find_by_name(brand_name) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/smartphone_finder/brand.rb', line 16 def self.find_by_name(brand_name) self.all.each do |b| if b.name.downcase==brand_name.downcase return b end end return SmartphoneFinder::Brand.new(brand_name,nil) end |
.list_brands ⇒ Object
33 34 35 |
# File 'lib/smartphone_finder/brand.rb', line 33 def self.list_brands self.list_all(self.all.collect { |obj| obj.name }) end |
Instance Method Details
#add_device(device) ⇒ Object
28 29 30 31 32 |
# File 'lib/smartphone_finder/brand.rb', line 28 def add_device(device) if !self.devices.detect{|obj| obj.name == device.name} devices.push(device) end end |
#list_devices ⇒ Object
36 37 38 |
# File 'lib/smartphone_finder/brand.rb', line 36 def list_devices self.list_all(self.devices.collect { |obj| obj.name }) end |