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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d4153e3ca5ba770ca3a10fcf7d1896aa51566521f5f4f560c2353d3fecdeee3
4
- data.tar.gz: dae113570a5189571ad80efc677a28cc7a9ddc02205f0b5690f44add8838a957
3
+ metadata.gz: 61b605527557fc96f8fbf0d526ee26a157d6dabf4544fbb8d3519197ad0ec45f
4
+ data.tar.gz: be89647509157f9cab923b498f90b129c3cdb00836e3d8a3c2af5e692252f155
5
5
  SHA512:
6
- metadata.gz: 8fca692ec9b1f113476c1568b7beb45895e5cb3f1b7bfdbefa3076f70b44bc1b40a7bc51b46d84bd8c87eb7d384858048e5c2c9b64a11c23ebcfce8476f9de02
7
- data.tar.gz: c453cd1c2cdaa59f18305ead427843313ba400450daead5db39f16090ec092e4e7395413f3a364028b69bf9d43fc164551a306146105a631610a077ddf075fc7
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 = { note: "note",
4
- highlight: "highlight",
5
- bookmark: "bookmark",
6
- clip: "clip" }
7
-
8
- attr_reader :book_title, :book_author, :text, :desc, :type, :loc, :loc_start, :page, :time
9
-
10
- def initialize(attrs)
11
- @book_title = attrs[:book_title]
12
- @book_author = attrs[:book_author]
13
- @text = attrs[:text]
14
- @desc = attrs[:desc]
15
- @type = attrs[:type]
16
- @loc = attrs[:loc]
17
- # This is our comparable, we need it as a number.
18
- @loc_start = attrs[:loc_start].to_i
19
- @page = attrs[:page]
20
- @time = attrs[:time]
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? && (! @loc_start.nil? || ! @page.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
 
@@ -9,22 +9,27 @@ module Fyodor
9
9
  end
10
10
 
11
11
  def entry
12
- Entry.new({book_title: book[:title],
13
- book_author: book[:author],
14
- text: text,
15
- desc: desc,
16
- type: type,
17
- loc: loc,
18
- loc_start: loc_start,
19
- page: page,
20
- time: time})
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
- title, author = @lines[0].scan(regex_cap(:title_author)).first
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 { |type| @lines[1] =~ regex_type(type) }
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
- @lines[1][regex_cap(:loc), 1]
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
- @lines[1][regex_cap(:loc_start), 1].to_i
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
- @lines[1][regex_cap(:page), 1]
52
- end
67
+ keyword = Regexp.quote(@config["page"])
68
+ regex = /#{keyword} (\S+)/i
53
69
 
54
- def time
55
- @lines[1][regex_cap(:time), 1]
70
+ @lines[1][regex, 1]
56
71
  end
57
72
 
58
- def text
59
- @lines[3..-2].join.strip
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 regex_type(type)
63
- s = Regexp.quote(@config[type])
64
- /^- #{s}/i
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 regex_cap(item)
68
- case item
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
@@ -1,3 +1,3 @@
1
1
  module Fyodor
2
- VERSION = "0.2.4".freeze
2
+ VERSION = "0.2.5".freeze
3
3
  end
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
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-13 00:00:00.000000000 Z
11
+ date: 2020-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: toml