pello 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d32c4a9f79d3c36e3cda541ccf908682b2c811737bafd68ad6667ce8c4a88ed4
4
- data.tar.gz: ed6ea93660c474a1c8819f36b0f23f67005cc43244bbcf4b6bcdf845cfa5f87c
3
+ metadata.gz: 2c85bd4f1d9080e27d0b8738141d556464c690f10b3cca2685aaaf79fa8d4511
4
+ data.tar.gz: 6fee889e4547385203fe90833fc959cab8fdf0cdf8bc084535ef7cba974a61cb
5
5
  SHA512:
6
- metadata.gz: 89bd026f7670e31b128deb18e95cd20f49d182a762df0a551ec27b1a328228463abdd51feb09fc2115e8dd91c4731211250adde30525c039a4b32553f3726374
7
- data.tar.gz: 5a7919fef10f857512cfc95d74548a8d692908256c5c937d369a3c335bfe647fd5115494677c3af6f46d707ad7ff10e9081b566443e1eef005e2d2a212c615c5
6
+ metadata.gz: 4a9d6a69228c7d7d3d1a05e9a2706d4e8692158345a603d32251ce283a7af0d2bbfd453a539ae0056edab0aa51dcbab0cf282dde939a77d00ec502211e3875b4
7
+ data.tar.gz: bd0c992649f399d3bdd95572859eb5a6c04d1805056d46a62866887f946e2d1bc96766a36398b58402c549b85aef3adb1cadf7cdef9b24d7d10c25b24566d180
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pello
4
+ module Actions
5
+ class AddPomodoriToCard
6
+ attr_reader :prompt
7
+
8
+ def initialize(prompt)
9
+ @prompt = prompt
10
+ end
11
+
12
+ def run(user, board_url, list_name)
13
+ board = Pello::Inputs.choose_board user, board_url
14
+ return unless board
15
+
16
+ puts board.as_table
17
+ continue = true
18
+ while continue
19
+ list = Pello::Inputs.choose_list board, list_name
20
+ return unless list
21
+
22
+ card = Pello::Inputs.choose_card list
23
+ next unless card
24
+
25
+ pomodori_before = card.extract_pomodori
26
+ pomodori_to_add = prompt.ask('Pomodori', default: 1)
27
+
28
+ new_name = name_with_added_pomodori(card, pomodori_to_add.to_i)
29
+
30
+ puts "Updating card #{card.name}"
31
+ puts "New title: #{new_name}"
32
+
33
+ if prompt.yes?('Confirm?')
34
+ card.name = new_name
35
+ card.save
36
+ card.log "[#{Time.now}] #{card.extract_name} (#{pomodori_before} -> #{card.extract_pomodori})", user
37
+ puts('Done!')
38
+ else
39
+ puts 'Ok, bye!'
40
+ nil
41
+ end
42
+
43
+ continue = prompt.yes?('Another one?')
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def name_with_added_pomodori(card, pomodori_to_add)
50
+ current_pomodori = card.extract_pomodori
51
+ current_points = card.extract_points
52
+ current_name = card.extract_name
53
+
54
+ result = []
55
+ result << "(#{current_points})" unless current_points.zero?
56
+ result << "#{current_pomodori + pomodori_to_add} 🍅"
57
+ result << current_name
58
+ result.join(' ')
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pello
4
+ module Actions
5
+ class MoveCard
6
+ attr_reader :prompt
7
+
8
+ def initialize(prompt)
9
+ @prompt = prompt
10
+ end
11
+
12
+ def run(user, board_url, list_name)
13
+ board = Pello::Inputs.choose_board user, board_url
14
+ return unless board
15
+
16
+ puts board.as_table
17
+ continue = true
18
+ while continue
19
+ source_list = Pello::Inputs.choose_list board, list_name, 'Choose source list'
20
+ return unless source_list
21
+
22
+ card = Pello::Inputs.choose_card source_list
23
+ next unless card
24
+
25
+ target_list = Pello::Inputs.choose_list board, list_name, 'Choose target list'
26
+ return unless target_list && target_list != source_list
27
+
28
+ puts "Moving card #{card.name} from \"#{source_list.name}\" to \"#{target_list.name}\""
29
+
30
+ if prompt.yes?('Confirm?')
31
+ card.list_id = target_list.id
32
+ card.save
33
+ card.log "[#{Time.now}] #{card.extract_name} (#{source_list.name} -> #{target_list.name})", user
34
+ puts('Done!')
35
+ else
36
+ puts 'Ok, bye!'
37
+ nil
38
+ end
39
+
40
+ continue = prompt.yes?('Another one?')
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
data/lib/pello/card.rb CHANGED
@@ -5,41 +5,30 @@ module Pello
5
5
  class Card
6
6
  extend Forwardable
7
7
 
8
- TITLE_REGEX = /(\(([0-9.]*)\))*\s*([0-9.]*)\s*🍅*\s*(.*)/.freeze
8
+ NAME_REGEX = /(\(([0-9.]*)\))*\s*([0-9.]*)\s*🍅*\s*(.*)/.freeze
9
9
  attr_accessor :trello_card
10
- def_delegators :@trello_card, :name, :name=, :comments, :add_comment, :save, :id
10
+ def_delegators :@trello_card, :name, :name=, :comments, :add_comment, :save, :id, :list_id, :list_id=
11
11
 
12
12
  def initialize(trello_card)
13
13
  @trello_card = trello_card
14
14
  end
15
15
 
16
16
  def extract_pomodori
17
- pomos = name.match(TITLE_REGEX)[3]
17
+ pomos = name.match(NAME_REGEX)[3]
18
18
  pomos ||= 0
19
19
  pomos.to_i
20
20
  end
21
21
 
22
- def extract_title
23
- name.match(TITLE_REGEX)[-1]
22
+ def extract_name
23
+ name.match(NAME_REGEX)[-1]
24
24
  end
25
25
 
26
26
  def extract_points
27
- points = name.match(TITLE_REGEX)[2]
27
+ points = name.match(NAME_REGEX)[2]
28
28
  points ||= 0
29
29
  points.to_f
30
30
  end
31
31
 
32
- def title_with_added_pomodori(how_many = 1)
33
- current_pomodori = extract_pomodori
34
- current_points = extract_points
35
- current_title = extract_title
36
- result = []
37
- result << "(#{current_points})" unless current_points.zero?
38
- result << "#{current_pomodori + how_many} 🍅"
39
- result << current_title
40
- result.join(' ')
41
- end
42
-
43
32
  def log(event, user)
44
33
  comment = comments.select { |c| c.creator_id == user.id && c.data['text'] =~ /PELLO LOG/ }.first
45
34
  if comment
data/lib/pello/config.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Pello
2
2
  class Config
3
3
  CONFIG_FILE_PATH = "#{ENV['HOME']}/.config/pello/pello.yaml".freeze
4
- attr_accessor :board_url, :developer_public_key, :list_name, :log_file, :member_token, :username, :error
4
+ attr_accessor :board_url, :developer_public_key, :list_name, :member_token, :username, :error
5
5
 
6
6
  def initialize
7
7
  if File.exist?(CONFIG_FILE_PATH)
@@ -15,7 +15,6 @@ module Pello
15
15
  @username = pello_config['username']
16
16
  @board_url = pello_config['board_url']
17
17
  @list_name = pello_config['list_name']
18
- @log_file = pello_config['log_file']
19
18
  @error = false
20
19
  else
21
20
  @error = true
@@ -39,7 +38,6 @@ module Pello
39
38
  file.puts ' board_url: ""'
40
39
  file.puts ' username: ""'
41
40
  file.puts ' list_name: "In progress"'
42
- file.puts ' log_file: "/Users/your_name/.pello_log"'
43
41
  end
44
42
  end
45
43
  end
data/lib/pello/inputs.rb CHANGED
@@ -15,12 +15,12 @@ module Pello
15
15
  Pello::Board.new(user.boards.detect { |b| b.name == input })
16
16
  end
17
17
 
18
- def self.choose_list(board, list_name)
18
+ def self.choose_list(board, list_name, prompt_text = 'Choose list')
19
19
  prompt = TTY::Prompt.new
20
20
  list_names = board.lists.map(&:name)
21
21
  list_names << BACK_OPTION
22
22
  default_list = board.lists.select { |l| l.name == list_name }.first.try(:name)
23
- input = prompt.select('Choose list', list_names, per_page: 15, default: default_list)
23
+ input = prompt.select(prompt_text, list_names, per_page: 15, default: default_list)
24
24
  return nil if input == BACK_OPTION
25
25
 
26
26
  Pello::List.new(board.lists.detect { |l| l.name == input })
data/lib/pello/list.rb CHANGED
@@ -4,7 +4,7 @@ module Pello
4
4
  class List
5
5
  extend Forwardable
6
6
  attr_accessor :trello_list
7
- def_delegators :@trello_list, :cards
7
+ def_delegators :@trello_list, :cards, :name, :id
8
8
 
9
9
  def initialize(trello_list)
10
10
  @trello_list = trello_list
data/lib/pello/runner.rb CHANGED
@@ -23,11 +23,14 @@ module Pello
23
23
  while continue
24
24
  case prompt.select('Choose task') do |menu|
25
25
  menu.choice name: 'Add pomodori', value: :add_pomodori
26
+ menu.choice name: 'Move card', value: :move_card
26
27
  menu.choice name: 'Edit config', value: :edit_config
27
28
  menu.choice name: 'quit', value: :quit
28
29
  end
29
30
  when :add_pomodori
30
31
  add_pomodori_to_card
32
+ when :move_card
33
+ move_card
31
34
  when :edit_config
32
35
  editor = ENV['EDITOR'] || 'vim'
33
36
  system 'mkdir -p ~/.config/pello'
@@ -41,44 +44,12 @@ module Pello
41
44
 
42
45
  private
43
46
 
44
- def file_log(text)
45
- File.open(@log_file_path, 'a+') do |file|
46
- file.puts(text)
47
- end
48
- end
49
-
50
47
  def add_pomodori_to_card
51
- board = Pello::Inputs.choose_board @user, @board_url
52
- return unless board
53
-
54
- puts board.as_table
55
- continue = true
56
- while continue
57
- list = Pello::Inputs.choose_list board, @list_name
58
- return unless list
59
-
60
- card = Pello::Inputs.choose_card list
61
- next unless card
62
-
63
- pomodori_before = card.extract_pomodori
64
- pomodori_to_add = prompt.ask('Pomodori', default: 1)
65
-
66
- puts "Updating card #{card.name}"
67
- puts "New title: #{card.title_with_added_pomodori(pomodori_to_add.to_i)}"
68
-
69
- if prompt.yes?('Confirm?')
70
- card.name = card.title_with_added_pomodori(pomodori_to_add.to_i)
71
- card.save
72
- file_log "[#{Time.now} - #{@user.full_name}] #{card.extract_title} (#{pomodori_before} -> #{card.extract_pomodori})"
73
- card.log "[#{Time.now} - #{@user.full_name}] #{card.extract_title} (#{pomodori_before} -> #{card.extract_pomodori})", @user
74
- puts('Done!')
75
- else
76
- puts 'Ok, bye!'
77
- nil
78
- end
48
+ Pello::Actions::AddPomodoriToCard.new(prompt).run(@user, board_url, list_name)
49
+ end
79
50
 
80
- continue = prompt.yes?('Another one?')
81
- end
51
+ def move_card
52
+ Pello::Actions::MoveCard.new(prompt).run(@user, board_url, list_name)
82
53
  end
83
54
 
84
55
  def configure_pello
@@ -92,7 +63,6 @@ module Pello
92
63
  @user = Trello::Member.find config.username
93
64
  @board_url = config.board_url
94
65
  @list_name = config.list_name
95
- @log_file_path = config.log_file
96
66
  else
97
67
  puts 'No config found, opening config file...'
98
68
  Pello::Config.write_empty_config
data/lib/pello/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pello
2
- VERSION = "0.2"
2
+ VERSION = "0.3"
3
3
  end
data/lib/pello.rb CHANGED
@@ -4,6 +4,8 @@ require 'pello/inputs'
4
4
  require 'pello/board'
5
5
  require 'pello/list'
6
6
  require 'pello/card'
7
+ require 'pello/actions/add_pomodori_to_card'
8
+ require 'pello/actions/move_card'
7
9
  require 'pello/config'
8
10
 
9
11
  module Pello
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pello
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrea Schiavini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-19 00:00:00.000000000 Z
11
+ date: 2022-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-trello
@@ -52,7 +52,8 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: Perform Trello operations like adding pomodori to a card title
55
+ description: Perform Trello operations like adding pomodori to a card name and moving
56
+ cards across lists
56
57
  email:
57
58
  - metalelf0@gmail.com
58
59
  executables:
@@ -62,6 +63,8 @@ extra_rdoc_files: []
62
63
  files:
63
64
  - bin/pello
64
65
  - lib/pello.rb
66
+ - lib/pello/actions/add_pomodori_to_card.rb
67
+ - lib/pello/actions/move_card.rb
65
68
  - lib/pello/board.rb
66
69
  - lib/pello/card.rb
67
70
  - lib/pello/config.rb