Class: OperatingSystem
Constant Summary
collapse
- @@all =
[]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#search_by_key, #search_by_name, #search_by_number
Constructor Details
Returns a new instance of OperatingSystem.
7
8
9
10
|
# File 'lib/operating_system.rb', line 7
def initialize(name= nil)
@name = name
@shortcuts = []
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/operating_system.rb', line 5
def name
@name
end
|
#shortcut ⇒ Object
Returns the value of attribute shortcut.
5
6
7
|
# File 'lib/operating_system.rb', line 5
def shortcut
@shortcut
end
|
Class Method Details
.all ⇒ Object
48
49
50
|
# File 'lib/operating_system.rb', line 48
def self.all
@@all
end
|
.create_operating_system(name) ⇒ Object
42
43
44
45
46
|
# File 'lib/operating_system.rb', line 42
def self.create_operating_system(name)
os = OperatingSystem.new(name)
os.save
os
end
|
.find_by_name(name) ⇒ Object
29
30
31
|
# File 'lib/operating_system.rb', line 29
def self.find_by_name(name)
@@all.detect {|os| os.name == name}
end
|
.find_or_create_operating_system(name) ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/operating_system.rb', line 33
def self.find_or_create_operating_system(name)
os = OperatingSystem.all.detect {|os_object| name == os_object.name}
if os.nil?
create_operating_system(name)
else
os
end
end
|
Instance Method Details
#add_shortcut(shortcut) ⇒ Object
20
21
22
23
|
# File 'lib/operating_system.rb', line 20
def add_shortcut(shortcut)
@shortcuts << shortcut
shortcut.operating_system = self
end
|
#save ⇒ Object
12
13
14
|
# File 'lib/operating_system.rb', line 12
def save
@@all << self
end
|
#shortcuts ⇒ Object
16
17
18
|
# File 'lib/operating_system.rb', line 16
def shortcuts
@shortcuts
end
|
#sort_alphabetically ⇒ Object
25
26
27
|
# File 'lib/operating_system.rb', line 25
def sort_alphabetically
@shortcuts = shortcuts.collect.sort_by {|obj| obj.name}
end
|