fyodor 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/fyodor/entry.rb +33 -19
- data/lib/fyodor/entry_parser.rb +44 -39
- data/lib/fyodor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61b605527557fc96f8fbf0d526ee26a157d6dabf4544fbb8d3519197ad0ec45f
|
4
|
+
data.tar.gz: be89647509157f9cab923b498f90b129c3cdb00836e3d8a3c2af5e692252f155
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dfc0e521bf352f1c98ac7d7f1203f8cccbd6491a9c216754dbc2ae3072a30361e688f8fe96014719043c3abac866022d7322ae3d5cb155657f434818ac624a1
|
7
|
+
data.tar.gz: 23c025a3c1bbdc206fa1d4cd4bfc6bccdd2e3de2a3735da74482d14c6cd5f74ed14cc834ac0851c5609c8be3aed1637e4312de405fb696594776a0c774731784
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ To read more about the motivation and what problem it tries to solve, [check thi
|
|
14
14
|
|
15
15
|
- Supports all the type of entries in your clippings file: highlights, notes, clips and bookmarks.
|
16
16
|
- Automatic removal of empty or duplicate entries (the clippings file can get a lot of those).
|
17
|
-
- Orders your entries by location on each book (the clippings file is ordered by time).
|
17
|
+
- Orders your entries by location/page on each book (the clippings file is ordered by time).
|
18
18
|
- Easily configurable for your language, allowing you to get all features and beautiful output.
|
19
19
|
- This software goes some length to be locale agnostic: basic parsing should work without configuration for any language. It should also work even if your clippings file has multiple locales.
|
20
20
|
- Bookmarks are printed together and notes are formatted differently, for better visualization.
|
data/lib/fyodor/entry.rb
CHANGED
@@ -1,23 +1,35 @@
|
|
1
1
|
module Fyodor
|
2
2
|
class Entry
|
3
|
-
TYPE = {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
3
|
+
TYPE = {
|
4
|
+
note: "note",
|
5
|
+
highlight: "highlight",
|
6
|
+
bookmark: "bookmark",
|
7
|
+
clip: "clip"
|
8
|
+
}
|
9
|
+
|
10
|
+
ATTRS = [
|
11
|
+
:book_title,
|
12
|
+
:book_author,
|
13
|
+
:text,
|
14
|
+
:desc,
|
15
|
+
:type,
|
16
|
+
:loc,
|
17
|
+
:loc_start,
|
18
|
+
:page,
|
19
|
+
:page_start,
|
20
|
+
:time
|
21
|
+
]
|
22
|
+
|
23
|
+
attr_reader *ATTRS
|
24
|
+
|
25
|
+
def initialize(args)
|
26
|
+
ATTRS.each do |attr|
|
27
|
+
instance_variable_set("@#{attr}", args[attr])
|
28
|
+
end
|
29
|
+
|
30
|
+
# These are our comparables. Let's make sure they are numbers.
|
31
|
+
@loc_start = @loc_start.to_i
|
32
|
+
@page_start = @page_start.to_i
|
21
33
|
|
22
34
|
raise ArgumentError, "Invalid Entry type" unless TYPE.value?(@type) || @type.nil?
|
23
35
|
end
|
@@ -31,11 +43,13 @@ module Fyodor
|
|
31
43
|
end
|
32
44
|
|
33
45
|
def desc_parsed?
|
34
|
-
! @type.nil? && (
|
46
|
+
! @type.nil? && (@loc_start != 0 || @page_start != 0)
|
35
47
|
end
|
36
48
|
|
37
49
|
# Override this method to use a SortedSet.
|
38
50
|
def <=>(other)
|
51
|
+
return @page_start <=> other.page_start if @loc_start == 0
|
52
|
+
|
39
53
|
@loc_start <=> other.loc_start
|
40
54
|
end
|
41
55
|
|
data/lib/fyodor/entry_parser.rb
CHANGED
@@ -9,22 +9,27 @@ module Fyodor
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def entry
|
12
|
-
Entry.new({
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
Entry.new({
|
13
|
+
book_title: book[:title],
|
14
|
+
book_author: book[:author],
|
15
|
+
text: text,
|
16
|
+
desc: desc,
|
17
|
+
type: type,
|
18
|
+
loc: loc,
|
19
|
+
loc_start: loc_start,
|
20
|
+
page: page,
|
21
|
+
page_start: page_start,
|
22
|
+
time: time
|
23
|
+
})
|
21
24
|
end
|
22
25
|
|
23
26
|
|
24
27
|
private
|
25
28
|
|
26
29
|
def book
|
27
|
-
|
30
|
+
regex = /^(.*) \((.*)\)\r?\n$/
|
31
|
+
|
32
|
+
title, author = @lines[0].scan(regex).first
|
28
33
|
# If book has no author, regex fails.
|
29
34
|
title = @lines[0] if title.nil?
|
30
35
|
|
@@ -36,51 +41,51 @@ module Fyodor
|
|
36
41
|
end
|
37
42
|
|
38
43
|
def type
|
39
|
-
Entry::TYPE.values.find
|
44
|
+
Entry::TYPE.values.find do |type|
|
45
|
+
keyword = Regexp.quote(@config[type])
|
46
|
+
regex = /^- #{keyword}/i
|
47
|
+
|
48
|
+
@lines[1] =~ regex
|
49
|
+
end
|
40
50
|
end
|
41
51
|
|
42
52
|
def loc
|
43
|
-
@
|
53
|
+
keyword = Regexp.quote(@config["loc"])
|
54
|
+
regex = /#{keyword} (\S+)/i
|
55
|
+
|
56
|
+
@lines[1][regex, 1]
|
44
57
|
end
|
45
58
|
|
46
59
|
def loc_start
|
47
|
-
@
|
60
|
+
keyword = Regexp.quote(@config["loc"])
|
61
|
+
regex = /#{keyword} (\d+)(-\d+)?/i
|
62
|
+
|
63
|
+
@lines[1][regex, 1].to_i
|
48
64
|
end
|
49
65
|
|
50
66
|
def page
|
51
|
-
@
|
52
|
-
|
67
|
+
keyword = Regexp.quote(@config["page"])
|
68
|
+
regex = /#{keyword} (\S+)/i
|
53
69
|
|
54
|
-
|
55
|
-
@lines[1][regex_cap(:time), 1]
|
70
|
+
@lines[1][regex, 1]
|
56
71
|
end
|
57
72
|
|
58
|
-
def
|
59
|
-
@
|
73
|
+
def page_start
|
74
|
+
keyword = Regexp.quote(@config["page"])
|
75
|
+
regex = /#{keyword} (\d+)(-\d+)?/i
|
76
|
+
|
77
|
+
@lines[1][regex, 1].to_i
|
60
78
|
end
|
61
79
|
|
62
|
-
def
|
63
|
-
|
64
|
-
|
80
|
+
def time
|
81
|
+
keyword = Regexp.quote(@config["time"])
|
82
|
+
regex = /#{keyword} (.*)\r?\n$/i
|
83
|
+
|
84
|
+
@lines[1][regex, 1]
|
65
85
|
end
|
66
86
|
|
67
|
-
def
|
68
|
-
|
69
|
-
when :title_author
|
70
|
-
/^(.*) \((.*)\)\r?\n$/
|
71
|
-
when :loc
|
72
|
-
s = Regexp.quote(@config["loc"])
|
73
|
-
/#{s} (\S+)/i
|
74
|
-
when :loc_start
|
75
|
-
s = Regexp.quote(@config["loc"])
|
76
|
-
/#{s} (\d+)(-\d+)?/i
|
77
|
-
when :page
|
78
|
-
s = Regexp.quote(@config["page"])
|
79
|
-
/#{s} (\S+)/i
|
80
|
-
when :time
|
81
|
-
s = Regexp.quote(@config["time"])
|
82
|
-
/#{s} (.*)\r?\n$/i
|
83
|
-
end
|
87
|
+
def text
|
88
|
+
@lines[3..-2].join.strip
|
84
89
|
end
|
85
90
|
|
86
91
|
def format_check
|
data/lib/fyodor/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fyodor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Cavalcanti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: toml
|