verkilo 0.1.3 → 0.1.4

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
  SHA1:
3
- metadata.gz: 8a804a5fee54435a3809b04e8eeb73bd58f33258
4
- data.tar.gz: 7e4a2b03cec74905dc2c7db48572ad00ccce33b3
3
+ metadata.gz: ea3913e2a234af2fa652f63922086996d971a9ac
4
+ data.tar.gz: e88c56a82aec9606c00f19055aef43e099d6fb77
5
5
  SHA512:
6
- metadata.gz: c90f8c77c7c957630df796fe6b5f811a242491f0b45a0b13fb43602e9fa72f6def30dfd6b2824ac6943d9e600012c2cce77a9056d3927bd1eb6a25484d3f16f1
7
- data.tar.gz: 81b1d192a9f4ea2ef9845e7c9c546f59709e533ff3923cc7b32e2ae2e2f49228d42bf8840284bbcab0af1c9dd95535831597ceca00fdfc8d29df1dbdd40568c1
6
+ metadata.gz: 59bf54e43d5fce6fe13b87a9de066501b59147fbac5bd3ff7f34b3f8c509db6fb62eea2f4a322305acb527eee1e92b1a85a528bdeb59f8b2e21fdaf533084183
7
+ data.tar.gz: a4f115464fd959a322025f09001c9b1a108171674097eef40d960d79f0eb153ce8e200a1fbe1f0ba918c7504d83e6f28b3cdc37384d3cf2060f6c282f7310e48
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- verkilo (0.1.3)
4
+ verkilo (0.1.4)
5
5
  thor (~> 0)
6
6
 
7
7
  GEM
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+
3
+ rake build;
4
+ gem install pkg/*.gem ;
5
+ # cd ../../Writing/pms-series
6
+ # # basename `git rev-parse --show-toplevel`
7
+ # basename -s .git `git config --get remote.origin.url`
8
+ # verkilo compile
9
+ # cd ../../Verkilo/verkilo-gem
@@ -4,7 +4,9 @@ module Verkilo
4
4
  @title = title
5
5
  @root_dir = root_dir
6
6
  @resource_dir = File.join(File.dirname(File.expand_path(__FILE__)), '../../resources')
7
- @contents = ""
7
+ @contents = nil
8
+ @wc = nil
9
+ @files = nil
8
10
  @today = Time.now.strftime("%F")
9
11
  @repo = repo
10
12
  @bib = Dir["#{@root_dir}/**/*.bib"].first || nil
@@ -12,8 +14,7 @@ module Verkilo
12
14
  end
13
15
 
14
16
  def contents
15
- @contents unless @contents.nil?
16
- @contents = files.map { |f| File.open(f,'r').read }.join("\n\n")
17
+ @contents ||= files.map { |f| File.open(f,'r').read }.join("\n\n")
17
18
  end
18
19
 
19
20
  def to_s
@@ -22,7 +23,7 @@ module Verkilo
22
23
  alias title to_s
23
24
 
24
25
  def to_i
25
- self.contents.gsub(/[^a-zA-Z\s\d]/,"").split(/\W+/).count
26
+ @wc ||= self.contents.gsub(/[^a-zA-Z\s\d]/,"").split(/\W+/).count
26
27
  end
27
28
  alias wordcount to_i
28
29
 
@@ -44,7 +45,7 @@ module Verkilo
44
45
 
45
46
  protected
46
47
  def files
47
- Dir["./#{@root_dir}/**/*.md"].sort
48
+ @files ||= Dir["#{@root_dir}/**/*.md"].sort
48
49
  end
49
50
  def epub_image
50
51
  fname = File.join(['.', 'covers', "#{@title}-epub.png"])
@@ -35,33 +35,41 @@ LONGDESC
35
35
 
36
36
  desc "wordcount", "Wordcount the books in the repository and write to YAML file."
37
37
  map %w(-w --wordcount) => :wordcount
38
+ method_option :log, :type => :boolean
39
+ method_option :delta, :type => :boolean
38
40
  method_option :offset
39
41
  long_desc <<-LONGDESC
40
42
  `verkilo wordcount` will count all the words
41
- \x5 in Markdown files in .book directories. The
42
- \x5 result will be added to a wordcount log YAML
43
- \x5 file inside the project's Verkilo configuration
44
- \x5 directory.
43
+ \x5 in Markdown files in .book directories.
45
44
 
46
- You can optionally specify a second parameter,
47
- \x5 which will offset the date based on timezone.
48
- \x5 This is helpful when you are running this via
49
- \x5 a server or CI platform that uses a different
50
- \x5 timezone from your own.
45
+ With the --log flag, the result will be added
46
+ \x5 to a wordcount log YAML file inside the
47
+ \x5 project's Verkilo configuration directory.
48
+
49
+ With the --offset flag, which will offset the
50
+ \x5 date based on timezone.This is helpful
51
+ \x5 when you are running this viaa server or
52
+ \x5 CI platform that uses a different timezone
53
+ \x5 from your own. (E.g. Github runs UTC)
51
54
 
52
55
  See the Verkilo website (https://verkilo.com) for details
53
56
 
54
- > $ verkilo wordcount --offset=-08:00
57
+ > $ verkilo wordcount --offset=-08:00 --log
55
58
  LONGDESC
56
59
  def wordcount
57
60
  is_verkilo_project!
61
+ log = options["log"] || false
58
62
  offset = options["offset"] || nil
63
+ delta = options["delta"] || false
59
64
  shelf = Verkilo::Shelf.new(root_dir)
60
- wc_log = Verkilo::Log.new('wordcount',root_dir, offset)
61
- wc_log.data = shelf.wordcount
62
- wc_log.write
63
-
64
- say "Wordcount for #{shelf}: #{shelf.wordcount.to_yaml}Written to #{wc_log.filename}"
65
+ say "Wordcount for #{shelf}: #{shelf.wordcount.to_yaml}"
66
+ if log
67
+ wc_log = Verkilo::Log.new('wordcount',root_dir, offset)
68
+ wc_log.data = shelf.wordcount
69
+ wc_log.delta! unless delta.nil?
70
+ wc_log.write
71
+ say "Written to #{wc_log.filename}"
72
+ end
65
73
  end
66
74
  desc "version", "Prints the Verkilo's version information"
67
75
  map %w(-v --version) => :version
@@ -8,6 +8,26 @@ module Verkilo
8
8
  @data = YAML.load(read_file)
9
9
  @today = Time.now.getlocal(offset).strftime("%F")
10
10
  end
11
+ def delta!(target='_total')
12
+ change = 0
13
+ last = nil
14
+ keys = @data.keys
15
+ ckey = target.sub(/_/,'_Δ')
16
+ until keys.empty? do
17
+ k = keys.shift
18
+ total!(k)
19
+ now = @data[k][target] || 0
20
+ change = (last.nil?) ? 0 : now - last
21
+ @data[k].merge!({ckey => change})
22
+ last = now
23
+ end
24
+ end
25
+ def total!(k=nil)
26
+ k ||= @today
27
+ @data[k]["_total"] = @data[k].map {
28
+ |k,v| (/^_/.match?(k)) ? 0 : v
29
+ }.inject(0, :+)
30
+ end
11
31
  def data=(h)
12
32
  @data = @data.merge({@today => h})
13
33
  end
@@ -1,3 +1,3 @@
1
1
  module Verkilo
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/test.sh ADDED
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+
3
+ rake build;
4
+ gem install pkg/*.gem ;
5
+ cd ../../Writing/pms-series
6
+ # basename `git rev-parse --show-toplevel`
7
+ basename -s .git `git config --get remote.origin.url`
8
+ verkilo wordcount --delta #--offset=-08:00
9
+ cd ../../Verkilo/verkilo-gem
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verkilo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben W
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-25 00:00:00.000000000 Z
11
+ date: 2020-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -76,6 +76,7 @@ files:
76
76
  - bin/console
77
77
  - bin/setup
78
78
  - bin/verkilo
79
+ - build.sh
79
80
  - lib/verkilo.rb
80
81
  - lib/verkilo/book.rb
81
82
  - lib/verkilo/cli.rb
@@ -101,6 +102,7 @@ files:
101
102
  - resources/track-changes.lua
102
103
  - resources/user.css
103
104
  - resources/yaml.md
105
+ - test.sh
104
106
  - verkilo.gemspec
105
107
  homepage: https://verkilo.com
106
108
  licenses: