Class: Lionel::ProxyCard

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/lionel/proxy_card.rb

Constant Summary collapse

MAX_ACTIONS =
1000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(card) ⇒ ProxyCard

Returns a new instance of ProxyCard.



9
10
11
# File 'lib/lionel/proxy_card.rb', line 9

def initialize(card)
  @card = card
end

Instance Attribute Details

#cardObject (readonly)

Returns the value of attribute card.



5
6
7
# File 'lib/lionel/proxy_card.rb', line 5

def card
  @card
end

Instance Method Details

#action_date(&block) ⇒ Object



23
24
25
26
27
28
# File 'lib/lionel/proxy_card.rb', line 23

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

#actions(options = {}) ⇒ Object



18
19
20
21
# File 'lib/lionel/proxy_card.rb', line 18

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

#checklist_count(name) ⇒ Object



66
67
68
69
70
# File 'lib/lionel/proxy_card.rb', line 66

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

#date_moved_to(list_name) ⇒ Object



30
31
32
33
34
# File 'lib/lionel/proxy_card.rb', line 30

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

#due_dateObject



62
63
64
# File 'lib/lionel/proxy_card.rb', line 62

def due_date
  format_date(due) if due
end

#estimateObject



56
57
58
59
60
# File 'lib/lionel/proxy_card.rb', line 56

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

#first_action(&block) ⇒ Object



40
41
42
# File 'lib/lionel/proxy_card.rb', line 40

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

#format_date(date, format = "%m/%d/%Y") ⇒ Object



36
37
38
# File 'lib/lionel/proxy_card.rb', line 36

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

#labelsObject



52
53
54
# File 'lib/lionel/proxy_card.rb', line 52

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


13
14
15
# File 'lib/lionel/proxy_card.rb', line 13

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

#projectObject



48
49
50
# File 'lib/lionel/proxy_card.rb', line 48

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

#typeObject



44
45
46
# File 'lib/lionel/proxy_card.rb', line 44

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