Class: CodeLabs::Tech
- Inherits:
-
Object
- Object
- CodeLabs::Tech
- Defined in:
- lib/code_labs/tech.rb
Overview
require ‘pry’
Constant Summary collapse
- @@all =
A peice of tech covered in the lab
Example:
CodeLabs::Tech.new(name) <- does not add to .all CodeLabs::Tech.create(name) <- does add to .all CodeLabs::Tech.find_or_create(name) <- will return the tech if it exists or will return a new oneArguments:
title, duration, link, author, last_updated []
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
<- The manager.
Class Method Summary collapse
- .all ⇒ Object
- .clear_all ⇒ Object
- .create(name) ⇒ Object
-
.find_or_create(name) ⇒ Object
<- the meat of the creation.
Instance Method Summary collapse
-
#add_lab(lab) ⇒ Object
<- type enforcment.
-
#initialize(name) ⇒ Tech
constructor
All tech has a name, no?.
- #labs ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(name) ⇒ Tech
All tech has a name, no?
16 17 18 19 |
# File 'lib/code_labs/tech.rb', line 16 def initialize(name) # All tech has a name, no? @name = name @labs = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
<- The manager
14 15 16 |
# File 'lib/code_labs/tech.rb', line 14 def name @name end |
Class Method Details
.all ⇒ Object
33 34 35 |
# File 'lib/code_labs/tech.rb', line 33 def self.all @@all # <- the core of the cli listing is in here end |
.clear_all ⇒ Object
36 37 38 |
# File 'lib/code_labs/tech.rb', line 36 def self.clear_all @@all.clear # <- I do not think I ended up needing this end |
.create(name) ⇒ Object
39 40 41 |
# File 'lib/code_labs/tech.rb', line 39 def self.create(name) self.new(name).save # <- fancy end |
.find_or_create(name) ⇒ Object
<- the meat of the creation
42 43 44 45 |
# File 'lib/code_labs/tech.rb', line 42 def self.find_or_create(name) # <- the meat of the creation res = @@all.detect{|tech| tech.name == name} res ? res : self.create(name) end |
Instance Method Details
#add_lab(lab) ⇒ Object
<- type enforcment
27 28 29 30 31 |
# File 'lib/code_labs/tech.rb', line 27 def add_lab(lab) # <- type enforcment raise TypeError unless lab.is_a?(CodeLabs::Lab) @labs << lab lab.add_tech(self) unless lab.techs.include?(self) # <- infinite loop end |
#labs ⇒ Object
24 25 26 |
# File 'lib/code_labs/tech.rb', line 24 def labs @labs.dup.freeze # <- no type editing here end |
#save ⇒ Object
20 21 22 23 |
# File 'lib/code_labs/tech.rb', line 20 def save @@all << self self # return the object not the list end |