Class: CodeLabs::Lab
- Inherits:
-
Object
- Object
- CodeLabs::Lab
- Defined in:
- lib/code_labs/lab.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
A single Lab on the page.
-
#duration ⇒ Object
A single Lab on the page.
-
#last_updated ⇒ Object
A single Lab on the page.
-
#link ⇒ Object
A single Lab on the page.
-
#title ⇒ Object
A single Lab on the page.
Instance Method Summary collapse
-
#add_tech(tech) ⇒ Object
<- enforce type and relationships.
-
#initialize(arguments = {}) ⇒ Lab
constructor
A new instance of Lab.
- #print_techs ⇒ Object
- #techs ⇒ Object
Constructor Details
#initialize(arguments = {}) ⇒ Lab
Returns a new instance of Lab.
15 16 17 18 19 20 21 22 |
# File 'lib/code_labs/lab.rb', line 15 def initialize(arguments={}) # default values @duration = "N/A" = "N/A" @techs = [] # Mass assignment arguments.each {|key, value| self.send("#{key}=", value) unless value == "" || value.nil?} # <- do not set the values if they are blank end |
Instance Attribute Details
#author ⇒ Object
A single Lab on the page
Example:
CodeLabs::Lab.new
or
CodeLabs::Lab.new(args)
Arguments:
title, duration, link, , last_updated
13 14 15 |
# File 'lib/code_labs/lab.rb', line 13 def end |
#duration ⇒ Object
A single Lab on the page
Example:
CodeLabs::Lab.new
or
CodeLabs::Lab.new(args)
Arguments:
title, duration, link, , last_updated
13 14 15 |
# File 'lib/code_labs/lab.rb', line 13 def duration @duration end |
#last_updated ⇒ Object
A single Lab on the page
Example:
CodeLabs::Lab.new
or
CodeLabs::Lab.new(args)
Arguments:
title, duration, link, , last_updated
13 14 15 |
# File 'lib/code_labs/lab.rb', line 13 def last_updated @last_updated end |
#link ⇒ Object
A single Lab on the page
Example:
CodeLabs::Lab.new
or
CodeLabs::Lab.new(args)
Arguments:
title, duration, link, , last_updated
13 14 15 |
# File 'lib/code_labs/lab.rb', line 13 def link @link end |
#title ⇒ Object
A single Lab on the page
Example:
CodeLabs::Lab.new
or
CodeLabs::Lab.new(args)
Arguments:
title, duration, link, , last_updated
13 14 15 |
# File 'lib/code_labs/lab.rb', line 13 def title @title end |
Instance Method Details
#add_tech(tech) ⇒ Object
<- enforce type and relationships
26 27 28 29 30 |
# File 'lib/code_labs/lab.rb', line 26 def add_tech(tech) # <- enforce type and relationships raise TypeError unless tech.is_a?(CodeLabs::Tech) @techs << tech tech.add_lab(self) unless tech.labs.include?(self) # <- potenial infinte loop end |
#print_techs ⇒ Object
31 32 33 |
# File 'lib/code_labs/lab.rb', line 31 def print_techs @techs.collect{|tech| tech.name}.join(', ') # <- Show all the related techs end |
#techs ⇒ Object
23 24 25 |
# File 'lib/code_labs/lab.rb', line 23 def techs @techs.dup.freeze # <- freeze so we keep type integrity end |