Sha256: f9fc1f84fbe774554a3fb99a3db0a1828d5145772f6ab6f767eae4098f1b65e6

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

module Nin
  class Item
    attr_accessor :id, :desc, :date, :tags, :completed, :archived

    def initialize(id,
                   desc,
                   date = Date.today,
                   tags = [],
                   completed = false,
                   archived = false,
                   formatter = Presenter::ItemPresenter)

      @id        = id
      @desc      = desc
      @date      = Date.parse_or_return(date) || Date.today
      @tags      = tags
      @completed = completed
      @archived  = archived
      @formatter = formatter.new(self)
    end

    def edit(desc, date = nil, tags = [])
      self.desc = desc
      self.date = date unless date.nil?
      self.tags.concat(tags)
    end

    def toggle_completed!
      @completed = !@completed
    end

    def toggle_archived!
      @archived = !@archived
    end

    def completed?
      @completed
    end

    def archived?
      @archived
    end

    def past?
      @date < Date.today
    end

    def today?
      @date == Date.today
    end

    def to_s
      @formatter.call
    end

    def to_h
      {
        'id' => id,
        'desc' => desc,
        'tags' => tags,
        'completed' => completed,
        'archived' => archived
      }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nin-1.0.1 lib/nin/item.rb
nin-1.0.0 lib/nin/item.rb