Sha256: 0902aa716f2b12ecca7d8446f87ec2749feb08d732d2f45116495bea7a30369b

Contents?: true

Size: 1.62 KB

Versions: 6

Compression:

Stored size: 1.62 KB

Contents

module Lionel
  class ProxyCard
    extend Forwardable

    attr_reader :card

    def_delegators :card, :id, :url, :name, :due

    def initialize(card)
      @card = card
    end

    def link(name = card.name)
      %Q[=HYPERLINK("#{card.url}", "#{name.gsub(/"/, "")}")]
    end

    MAX_ACTIONS = 1000
    def actions(options = {})
      options[:limit] = options.fetch(:limit, MAX_ACTIONS)
      @actions ||= card.actions(options).map { |a| Lionel::ProxyAction.new(a) }
    end

    def action_date(&block)
      filtered = actions.select(&block)
      return "" if filtered.empty?
      action = filtered.sort { |a, b| a.date <=> b.date }.first
      format_date action.date
    end

    def date_moved_to(list_name)
      action = first_action { |a| a.moved_to?(list_name) }
      return "" unless action
      format_date(action.date)
    end

    def format_date(date, format = "%m/%d/%Y")
      date.strftime(format)
    end

    def first_action(&block)
      actions.select(&block).sort { |a, b| a.date <=> b.date }.first
    end

    def type
      labels.detect { |l| l =~ %r{bug|chore|task}i } || 'story'
    end

    def project
      labels.detect { |l| l !~ %r{bug|chore|task}i }
    end

    def labels
      @labels ||= card.labels.map(&:name).map(&:downcase)
    end

    def estimate
      match = card.name.match(/\[(?<estimate>\w+)\]/)
      return "" unless match
      match[:estimate]
    end

    def due_date
      format_date(due) if due
    end

    def checklist_count(name)
      checklist = card.checklists.find { |chl| chl.name == name }
      return 0 unless checklist
      checklist.check_items.count
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lionel_richie-0.3.1 lib/lionel/proxy_card.rb
lionel_richie-0.3.0 lib/lionel/proxy_card.rb
lionel_richie-0.2.4 lib/lionel/proxy_card.rb
lionel_richie-0.2.3.1 lib/lionel/proxy_card.rb
lionel_richie-0.2.3 lib/lionel/proxy_card.rb
lionel_richie-0.2.1 lib/lionel/proxy_card.rb