Sha256: c7a96b909a9c9f9265753a11c3376bf264ceaafc7cde7c514c9c0f45c452b604

Contents?: true

Size: 797 Bytes

Versions: 2

Compression:

Stored size: 797 Bytes

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
conference_tracker-1.1.1 lib/conference_tracker/talk.rb
conference_tracker-1.1.0 lib/conference_tracker/talk.rb