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 +4 -4
- data/Gemfile.lock +1 -1
- data/build.sh +9 -0
- data/lib/verkilo/book.rb +6 -5
- data/lib/verkilo/cli.rb +23 -15
- data/lib/verkilo/log.rb +20 -0
- data/lib/verkilo/version.rb +1 -1
- data/test.sh +9 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea3913e2a234af2fa652f63922086996d971a9ac
|
4
|
+
data.tar.gz: e88c56a82aec9606c00f19055aef43e099d6fb77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59bf54e43d5fce6fe13b87a9de066501b59147fbac5bd3ff7f34b3f8c509db6fb62eea2f4a322305acb527eee1e92b1a85a528bdeb59f8b2e21fdaf533084183
|
7
|
+
data.tar.gz: a4f115464fd959a322025f09001c9b1a108171674097eef40d960d79f0eb153ce8e200a1fbe1f0ba918c7504d83e6f28b3cdc37384d3cf2060f6c282f7310e48
|
data/Gemfile.lock
CHANGED
data/build.sh
ADDED
data/lib/verkilo/book.rb
CHANGED
@@ -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
|
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["
|
48
|
+
@files ||= Dir["#{@root_dir}/**/*.md"].sort
|
48
49
|
end
|
49
50
|
def epub_image
|
50
51
|
fname = File.join(['.', 'covers', "#{@title}-epub.png"])
|
data/lib/verkilo/cli.rb
CHANGED
@@ -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.
|
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
|
-
|
47
|
-
\x5
|
48
|
-
\x5
|
49
|
-
|
50
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
data/lib/verkilo/log.rb
CHANGED
@@ -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
|
data/lib/verkilo/version.rb
CHANGED
data/test.sh
ADDED
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.
|
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-
|
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:
|