Sha256: f71738f3d794e32a06793d8b142f60a1d7bd5ba2668de17a746447999ca48c47

Contents?: true

Size: 836 Bytes

Versions: 7

Compression:

Stored size: 836 Bytes

Contents

require 'csv'

module Redpomo
  class Entry

    def self.load_from_csv(path)
      CSV.parse(File.read(path).split("\n")[4..-1].join("\n")).map do |data|
        Entry.new(data[0], DateTime.parse(data[1]), data[2].to_i * 60.0)
      end.sort_by { |entry| entry.datetime }
    end

    attr_reader :text, :datetime, :duration

    def initialize(text, datetime, duration)
      @text = text
      @datetime = datetime
      @duration = duration
    end

    def date
      datetime.to_date
    end

    def time
      datetime.to_time
    end

    def end_time
      time + duration
    end

    def same_date?(entry)
      date == entry.date
    end

    def same_text?(entry)
      text == entry.text
    end

    def to_task
      Task.new(nil, text)
    end

    def push!
      to_task.tracker.push_entry!(self)
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
redpomo-0.0.7 lib/redpomo/entry.rb
redpomo-0.0.6 lib/redpomo/entry.rb
redpomo-0.0.5 lib/redpomo/entry.rb
redpomo-0.0.4 lib/redpomo/entry.rb
redpomo-0.0.3 lib/redpomo/entry.rb
redpomo-0.0.2 lib/redpomo/entry.rb
redpomo-0.0.1 lib/redpomo/entry.rb