Class: ConferenceTracker::Talk

Inherits:
Object
  • Object
show all
Defined in:
lib/conference_tracker/talk.rb

Constant Summary collapse

RULE =
/(.*) (\d+min|#{Duration::UNITS.keys.join("|")})/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, duration) ⇒ Talk

Returns a new instance of Talk.



17
18
19
20
# File 'lib/conference_tracker/talk.rb', line 17

def initialize(name, duration)
  @name = name
  @duration = Duration.new(duration)
end

Class Method Details

.bulk(talks) ⇒ Object



13
14
15
# File 'lib/conference_tracker/talk.rb', line 13

def self.bulk(talks)
  talks.map { |talk| factory(talk) }.compact
end

.factory(talk) ⇒ Object



7
8
9
10
11
# File 'lib/conference_tracker/talk.rb', line 7

def self.factory(talk)
  matching = talk.match(RULE)
  return unless matching
  new(*matching.captures)
end

Instance Method Details

#schedule(time) ⇒ Object



34
35
36
37
# File 'lib/conference_tracker/talk.rb', line 34

def schedule(time)
  @start = ConferenceTracker.parse(time)
  self
end

#scheduled?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/conference_tracker/talk.rb', line 39

def scheduled?
  !!@start
end

#to_iObject



30
31
32
# File 'lib/conference_tracker/talk.rb', line 30

def to_i
  @duration.to_i
end

#to_sObject



22
23
24
25
26
27
28
# File 'lib/conference_tracker/talk.rb', line 22

def to_s
  [].tap do |s|
    s << @start.strftime(FORMAT) if @start
    s << @name
    s << @duration
  end.compact.join(" ")
end