kindleclippings 1.3.4 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kindleclippings/clipping.rb +41 -0
- data/lib/kindleclippings/clippingresult.rb +8 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b5b979eb007eca1eaf64a0ac7d007b9e5dd7202
|
4
|
+
data.tar.gz: 0b9b507b53a5eef08362b997f293d569c6e367c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bf1cf4de4a38c75d5dea2652cd8b1befec002caad05911fa6c4f9994be2a4f5df8a8cabadf7422e264d5e32bc5ae2e1934a148541401aee1255f858fbee18db
|
7
|
+
data.tar.gz: c1b79c4ab2adcd6472055507eb0d00577a8a050ef348084f944069e44da261dc51f15c8e81a46a1d1eee566626e7aaa3ac3e5c0abe6fc51427b09a5c65737ffb
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module KindleClippings
|
3
3
|
class Clipping
|
4
|
+
include Comparable
|
5
|
+
|
4
6
|
require 'date'
|
5
7
|
|
6
8
|
attr_accessor :book_title, :author, :type, :location, :added_on, :content, :page
|
@@ -36,5 +38,44 @@ module KindleClippings
|
|
36
38
|
"- #{@type} #{('on Page ' + @page.to_s + ' | ') if @page > 0}Loc. #{@location} | Added on #{@added_on.strftime('%A, %B %d, %Y, %I:%M %p')}\n\n" +
|
37
39
|
"#{@content}"
|
38
40
|
end
|
41
|
+
|
42
|
+
def <=>(other_clipping)
|
43
|
+
if @book_title != other_clipping.book_title
|
44
|
+
return @book_title <=> other_clipping.book_title
|
45
|
+
end
|
46
|
+
# Same book
|
47
|
+
|
48
|
+
if @page != other_clipping.page
|
49
|
+
return @page <=> other_clipping.page
|
50
|
+
end
|
51
|
+
# Same book and page
|
52
|
+
|
53
|
+
if @location != other_clipping.location
|
54
|
+
return locations_cmp(@location, other_clipping.location)
|
55
|
+
end
|
56
|
+
# Same book, page and location
|
57
|
+
|
58
|
+
@added_on <=> other_clipping.added_on
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def locations_cmp(a, b)
|
64
|
+
return 0 if a == b
|
65
|
+
|
66
|
+
a_parts = a.split('-').map(&:to_i)
|
67
|
+
b_parts = b.split('-').map(&:to_i)
|
68
|
+
|
69
|
+
if a_parts[0] != b_parts[0] # beginning differs
|
70
|
+
return a_parts[0] <=> b_parts[0] # compare by beginning
|
71
|
+
end
|
72
|
+
# Same beginning
|
73
|
+
|
74
|
+
if a_parts[1].nil? || b_parts[1].nil? # end missing from a location
|
75
|
+
return 0 # consider equal
|
76
|
+
end
|
77
|
+
|
78
|
+
a_parts[1] <=> b_parts[1] # compare by end
|
79
|
+
end
|
39
80
|
end
|
40
81
|
end
|
@@ -31,7 +31,14 @@ module KindleClippings
|
|
31
31
|
|
32
32
|
def filter_by_property(property, value)
|
33
33
|
return self unless value
|
34
|
-
|
34
|
+
|
35
|
+
if value.is_a?(Regexp)
|
36
|
+
select_blk = lambda {|annotation| annotation.send(property) =~ value }
|
37
|
+
else
|
38
|
+
select_blk = lambda {|annotation| annotation.send(property).casecmp(value) == 0 }
|
39
|
+
end
|
40
|
+
|
41
|
+
self.select(&select_blk)
|
35
42
|
end
|
36
43
|
|
37
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kindleclippings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Alexander Boe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|