Class: CodeLabs::Lab

Inherits:
Object
  • Object
show all
Defined in:
lib/code_labs/lab.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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"
    @author = "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

#authorObject

A single Lab on the page

Example:

CodeLabs::Lab.new
or
CodeLabs::Lab.new(args)

Arguments:

title, duration, link, author, last_updated


13
14
15
# File 'lib/code_labs/lab.rb', line 13

def author
  @author
end

#durationObject

A single Lab on the page

Example:

CodeLabs::Lab.new
or
CodeLabs::Lab.new(args)

Arguments:

title, duration, link, author, last_updated


13
14
15
# File 'lib/code_labs/lab.rb', line 13

def duration
  @duration
end

#last_updatedObject

A single Lab on the page

Example:

CodeLabs::Lab.new
or
CodeLabs::Lab.new(args)

Arguments:

title, duration, link, author, last_updated


13
14
15
# File 'lib/code_labs/lab.rb', line 13

def last_updated
  @last_updated
end

A single Lab on the page

Example:

CodeLabs::Lab.new
or
CodeLabs::Lab.new(args)

Arguments:

title, duration, link, author, last_updated


13
14
15
# File 'lib/code_labs/lab.rb', line 13

def link
  @link
end

#titleObject

A single Lab on the page

Example:

CodeLabs::Lab.new
or
CodeLabs::Lab.new(args)

Arguments:

title, duration, link, author, 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

Raises:

  • (TypeError)


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


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

#techsObject



23
24
25
# File 'lib/code_labs/lab.rb', line 23

def techs
    @techs.dup.freeze # <- freeze so we keep type integrity

end