Class: Pello::Card

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pello/card.rb

Constant Summary collapse

TITLE_REGEX =
/(\(([0-9.]*)\))*\s*([0-9.]*)\s*🍅*\s*(.*)/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(trello_card) ⇒ Card

Returns a new instance of Card.



12
13
14
# File 'lib/pello/card.rb', line 12

def initialize(trello_card)
  @trello_card = trello_card
end

Instance Attribute Details

#trello_cardObject

Returns the value of attribute trello_card.



9
10
11
# File 'lib/pello/card.rb', line 9

def trello_card
  @trello_card
end

Instance Method Details

#extract_pointsObject



26
27
28
29
30
# File 'lib/pello/card.rb', line 26

def extract_points
  points = name.match(TITLE_REGEX)[2]
  points ||= 0
  points.to_f
end

#extract_pomodoriObject



16
17
18
19
20
# File 'lib/pello/card.rb', line 16

def extract_pomodori
  pomos = name.match(TITLE_REGEX)[3]
  pomos ||= 0
  pomos.to_i
end

#extract_titleObject



22
23
24
# File 'lib/pello/card.rb', line 22

def extract_title
  name.match(TITLE_REGEX)[-1]
end

#log(event, user) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pello/card.rb', line 43

def log(event, user)
  comment = comments.select { |c| c.creator_id == user.id && c.data['text'] =~ /PELLO LOG/ }.first
  if comment
    new_text = [comment.data['text'], event].join("\n")
    comment.delete
    add_comment new_text
  else
    text = ['~~~PELLO LOG', event].join("\n")
    add_comment text
  end
end

#title_with_added_pomodori(how_many = 1) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/pello/card.rb', line 32

def title_with_added_pomodori(how_many = 1)
  current_pomodori = extract_pomodori
  current_points = extract_points
  current_title = extract_title
  result = []
  result << "(#{current_points})" unless current_points.zero?
  result << "#{current_pomodori + how_many} 🍅"
  result << current_title
  result.join(' ')
end