Sha256: 4290530da949d4f522433f6e1d1ab6963b365e0bc54fa846edcc512f119065c3

Contents?: true

Size: 901 Bytes

Versions: 5

Compression:

Stored size: 901 Bytes

Contents

require "trello_flow/table"

module TrelloFlow
  module Api
    class Checklist < Base
      belongs_to :card
      #has_many :items, uri: "checklists/:checklist_id/checkItems"

      def self.fields
        [:name]
      end

      def select_or_create_item(item_name = nil)
        if item_name.present? || items.none?
          add_item (Cli.ask("Input to-do [#{card.name}]:").presence || card.name)
        else
          Table.pick(items, title: "#{card.name} (#{name})")
        end
      end

      def items
        attributes[:checkItems].map do |attr|
          Item.new attr.merge(checklist_id: id)
        end
      end

      def card_id
        attributes[:idCard]
      end

      private

        def add_item(name)
          Item.with("checklists/:checklist_id/checkItems").where(checklist_id: id).create(name: name)
          # items.create(name: name)
        end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
trello_flow-1.3.0 lib/trello_flow/api/checklist.rb
trello_flow-1.2.2 lib/trello_flow/api/checklist.rb
trello_flow-1.2.1 lib/trello_flow/api/checklist.rb
trello_flow-1.2.0 lib/trello_flow/api/checklist.rb
trello_flow-1.1.0 lib/trello_flow/api/checklist.rb