Class: SmartphoneFinder::Brand

Inherits:
Object
  • Object
show all
Extended by:
HelperMethods
Includes:
HelperMethods
Defined in:
lib/smartphone_finder/brand.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HelperMethods

list_all, obj_exist?

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

#devicesObject

Returns the value of attribute devices.



7
8
9
# File 'lib/smartphone_finder/brand.rb', line 7

def devices
  @devices
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/smartphone_finder/brand.rb', line 7

def name
  @name
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/smartphone_finder/brand.rb', line 7

def url
  @url
end

Class Method Details

.allObject



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_brandsObject



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_devicesObject



36
37
38
# File 'lib/smartphone_finder/brand.rb', line 36

def list_devices
    self.list_all(self.devices.collect { |obj| obj.name  })
end