require "conference_tracker/duration" module ConferenceTracker class Talk RULE = /(.*) (\d+min|#{Duration::UNITS.keys.join("|")})/ def self.factory(talk) matching = talk.match(RULE) return unless matching new(*matching.captures) end def self.bulk(talks) talks.map { |talk| factory(talk) }.compact end def initialize(name, duration) @name = name @duration = Duration.new(duration) end def to_s [].tap do |s| s << @start.strftime(FORMAT) if @start s << @name s << @duration end.compact.join(" ") end def to_i @duration.to_i end def schedule(time) @start = ConferenceTracker.parse(time) self end def scheduled? !!@start end end end