doing 1.0.63 → 1.0.64

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: c103e507e82866174c88e6c3613f613964eaacba5f499631598b9ecbbb0cbe55
4
- data.tar.gz: edb32425ba3e81c1e3ff5bfeed3d0cb0b2dd8c2a353bc3d6adee6b98bf3536e0
3
+ metadata.gz: 6e6ebff7b78368227b7642297b5b88c8f018f0a9049f42478fc070f545421b1c
4
+ data.tar.gz: bff5c3852e60db87cacaba489f30fcf93fbdb01a8b7e4cba5fd06b6fc23db936
5
5
  SHA512:
6
- metadata.gz: 20b03da63cba70b6c12a2f7775429f974fba8bc12b5f7c411d7a8e4a765f6c3113d3a627cf96684e4fbdb26c1b0430e0beec196cd0d2f655dd4459ba10b0902f
7
- data.tar.gz: 934a87ead078f5fa7d2b7260921bfdeb15a57ecddd7a793003ad7dabb5dbf5bc093c1048258ffaba41e0ad00f5d49ab26cbdb825cca5e7f21c30446d92e3b10e
6
+ metadata.gz: 3c987d7c4a54bb331a3d9db464c5e35b86b1bcc777418547067b8f3bf609756663990c42b53b12d0f36a536f86b3041943eacd539d4d0cf8d1610ff7f3333801
7
+ data.tar.gz: 514fa3c1e8acefc9ebfde3e71e517918648b57c6b52c6d2c86bc9fe79d555d158edae4a9a2dc54c91bbfc32962280e328d97e26875114d4e1b0c98f693923b04
data/README.md CHANGED
@@ -29,7 +29,7 @@ _Side note:_ I actually use the library behind this utility as part of another s
29
29
 
30
30
  ## Installation
31
31
 
32
- The current version of `doing` is <!--VER-->1.0.62<!--END VER-->.
32
+ The current version of `doing` is <!--VER-->1.0.63<!--END VER-->.
33
33
 
34
34
  $ [sudo] gem install doing
35
35
 
data/bin/doing CHANGED
@@ -1391,6 +1391,41 @@ command :undo do |c|
1391
1391
  end
1392
1392
  end
1393
1393
 
1394
+ desc 'Import entries from an external source'
1395
+ long_desc 'Imports entries from other sources. Currently only handles JSON reports exported from Timing.app.'
1396
+ arg_name 'PATH'
1397
+ command [:import] do |c|
1398
+ c.desc 'Import type'
1399
+ c.arg_name 'TYPE'
1400
+ c.flag [:type], default_value: 'timing'
1401
+
1402
+ c.desc 'Target section'
1403
+ c.arg_name 'NAME'
1404
+ c.flag %i[s section], default_value: wwid.current_section
1405
+
1406
+ c.desc 'Tag all imported entries'
1407
+ c.arg_name 'TAGS'
1408
+ c.flag [:tag]
1409
+
1410
+ c.desc 'Prefix entries with'
1411
+ c.arg_name 'PREFIX'
1412
+ c.flag [:prefix]
1413
+
1414
+ c.action do |_global_options, options, args|
1415
+
1416
+ section = wwid.guess_section(options[:s]) || options[:s].cap_first
1417
+
1418
+ if options[:type] =~ /^tim/i
1419
+ args.each do |path|
1420
+ wwid.import_timing(path, { section: section, tag: options[:tag], prefix: options[:prefix] })
1421
+ wwid.write(wwid.doing_file)
1422
+ end
1423
+ else
1424
+ raise 'Invalid import type'
1425
+ end
1426
+ end
1427
+ end
1428
+
1394
1429
  pre do |global, _command, _options, _args|
1395
1430
  if global[:config_file] && global[:config_file] != wwid.config_file
1396
1431
  wwid.config_file = global[:config_file]
data/lib/doing/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Doing
2
- VERSION = '1.0.63'
2
+ VERSION = '1.0.64'
3
3
  end
data/lib/doing/wwid.rb CHANGED
@@ -310,7 +310,7 @@ class WWID
310
310
  else
311
311
  @content[section]['items'][current - 1]['note'] = [] unless @content[section]['items'][current - 1].key? 'note'
312
312
 
313
- @content[section]['items'][current - 1]['note'].push(line.gsub(/ *$/, ''))
313
+ @content[section]['items'][current - 1]['note'].push(line.chomp)
314
314
  # end
315
315
  end
316
316
  end
@@ -667,6 +667,55 @@ class WWID
667
667
  @results.push(%(Added "#{entry['title']}" to #{section}))
668
668
  end
669
669
 
670
+ ##
671
+ ## @brief Imports a Timing report
672
+ ##
673
+ ## @param path (String) Path to JSON report file
674
+ ## @param section (String) The section to add to
675
+ ## @param opt (Hash) Additional Options
676
+ ##
677
+ def import_timing(path, opt = {})
678
+ section = opt[:section] || @current_section
679
+ add_section(section) unless @content.has_key?(section)
680
+
681
+ add_tags = opt[:tag] ? opt[:tag].split(/[ ,]+/).map { |t| t.sub(/^@?/, '@') }.join(' ') : ''
682
+ prefix = opt[:prefix] ? opt[:prefix] : '[Timing.app]'
683
+ raise "File not found" unless File.exist?(File.expand_path(path))
684
+
685
+ data = JSON.parse(IO.read(File.expand_path(path)))
686
+ new_items = []
687
+ data.each do |entry|
688
+ # Only process task entries
689
+ next if entry.key?('activityType') && entry['activityType'] != 'Task'
690
+ # Only process entries with a start and end date
691
+ next unless entry.key?('startDate') && entry.key?('endDate')
692
+
693
+ start_time = Time.parse(entry['startDate'])
694
+ end_time = Time.parse(entry['endDate'])
695
+ next unless start_time && end_time
696
+ tags = entry['project'].split(/ ▸ /).map {|proj| proj.gsub(/ +/, '').downcase }
697
+ title = "#{prefix} "
698
+ title += entry.key?('activityTitle') && entry['activityTitle'] != '(Untitled Task)' ? entry['activityTitle'] : 'Working on'
699
+ tags.each do |tag|
700
+ if title =~ /\b#{tag}\b/i
701
+ title.sub!(/\b#{tag}\b/i, "@#{tag}")
702
+ else
703
+ title += " @#{tag}"
704
+ end
705
+ end
706
+ title = autotag(title) if @auto_tag
707
+ title += " @done(#{end_time.strftime('%Y-%m-%d %H:%M')})"
708
+ title.gsub!(/ +/, ' ')
709
+ title.strip!
710
+ new_entry = { 'title' => title, 'date' => start_time, 'section' => section }
711
+ new_entry['note'] = entry['notes'].split(/\n/).map(&:chomp) if entry.key?('notes')
712
+ new_items.push(new_entry)
713
+ end
714
+
715
+ @content[section]['items'].concat(new_items)
716
+ @results.push(%(Imported #{new_items.count} items to #{section}))
717
+ end
718
+
670
719
  ##
671
720
  ## @brief Return the content of the last note for a given section
672
721
  ##
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.63
4
+ version: 1.0.64
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-17 00:00:00.000000000 Z
11
+ date: 2021-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake