kindleclippings 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown CHANGED
@@ -63,4 +63,10 @@ You can filter the results by author and booktitle by using the methods `by_auth
63
63
 
64
64
  clippings.by_author('Malcolm Gladwell') # All annotations for all the books by Malcolm Gladwell
65
65
 
66
- clippings.by_book('Born to Run') # All annotations for the book Born to Run
66
+ clippings.by_book('Born to Run') # All annotations for the book Born to Run
67
+
68
+ ## Contributors
69
+
70
+ * Georg Alexander Bøe
71
+ * Masatomo Nakano
72
+ * brokensandals
File without changes
@@ -0,0 +1,10 @@
1
+ class String
2
+ unless "".respond_to?(:lines)
3
+ require "enumerator"
4
+
5
+ def lines
6
+ to_a.enum_for(:each)
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,7 @@
1
+ class Symbol
2
+ unless :symbol.respond_to?(:downcase)
3
+ def downcase
4
+ self.to_s.downcase.intern
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+ module KindleClippings
3
+
4
+ class Parser
5
+
6
+ def parse_file(path)
7
+ file_content = open(path, 'r:utf-8').read
8
+
9
+ parse(file_content)
10
+ end
11
+
12
+ def parse(filecontent)
13
+ @clippings = ClippingResult.new
14
+
15
+ filecontent.split("=" * 10).each do |clipping|
16
+
17
+ a_clipping = parse_clipping(clipping)
18
+
19
+ if a_clipping
20
+ @clippings << a_clipping
21
+ end
22
+
23
+
24
+ end
25
+ @clippings
26
+ end
27
+
28
+ private
29
+
30
+ def parse_clipping(clipping)
31
+ clipping.lstrip!
32
+
33
+ lines = clipping.lines.to_a
34
+
35
+ if lines.length < 4
36
+ return nil
37
+ end
38
+
39
+ first_line = lines[0].strip.scan(/^(.+) \((.+)\)$/i).first
40
+ second_line = lines[1].strip.scan(/^- (.+?) Loc. ([0-9-]*?) +\| Added on (.+)$/i).first
41
+
42
+ title, author = *first_line
43
+ type, location, date = *second_line
44
+
45
+ content = lines[3..-1].join("")
46
+
47
+ Clipping.new(title, author, type.to_sym, location, date, content.strip)
48
+ end
49
+ end
50
+ end
@@ -1,65 +1,5 @@
1
- # encoding: utf-8
2
- module KindleClippings
3
-
4
- class Parser
5
- ['clipping', 'clippingresult'].each { |file| require File.expand_path(File.dirname(__FILE__) + '/' + file) }
6
-
7
- def parse_file(path)
8
-
9
- file_content = String.new
10
-
11
- if RUBY_VERSION =~ /^1\.8/
12
- file_content = open(path).read
13
- else
14
- file_content = File.open(path, :encoding => "UTF-8").read
15
- end
16
-
17
- parse(file_content)
18
- end
19
-
20
- def parse(filecontent)
21
- @clippings = ClippingResult.new
22
-
23
- filecontent.split("=" * 10).each do |clipping|
24
-
25
- a_clipping = parse_clipping(clipping)
26
-
27
- if a_clipping
28
- @clippings << a_clipping
29
- end
30
-
31
-
32
- end
33
- @clippings
34
- end
35
-
36
- private
37
-
38
- def parse_clipping(clipping)
39
- clipping.lstrip!
40
-
41
- lines = Array.new
42
-
43
- if RUBY_VERSION >= "1.9.1"
44
- lines = clipping.lines.to_a
45
- else
46
- lines = clipping.to_a
47
- end
48
-
49
- if lines.length < 4
50
- return nil
51
- end
52
-
53
- first_line = lines[0].strip.scan(/^(.+) \((.+)\)$/i).first
54
- second_line = lines[1].strip.scan(/^- (.+?) Loc. ([0-9-]*?) \| Added on (.+)$/i).first
55
-
56
- title, author = *first_line
57
- type, location, date = *second_line
58
- content = String.new
59
-
60
- content = lines[3..-1].join("")
61
-
62
- Clipping.new(title, author, type.to_sym, location, date, content.strip)
63
- end
64
- end
65
- end
1
+ require 'kindleclippings/clipping'
2
+ require 'kindleclippings/clippingresult'
3
+ require 'kindleclippings/parser'
4
+ require 'kindleclippings/core_ext/string'
5
+ require 'kindleclippings/core_ext/symbol'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 2
8
- - 1
9
- version: 1.2.1
8
+ - 2
9
+ version: 1.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Georg Alexander Boe
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-21 00:00:00 +02:00
17
+ date: 2010-10-06 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -42,9 +42,12 @@ extra_rdoc_files:
42
42
  - LICENSE
43
43
  - README.markdown
44
44
  files:
45
- - lib/clipping.rb
46
- - lib/clippingresult.rb
47
45
  - lib/kindleclippings.rb
46
+ - lib/kindleclippings/clipping.rb
47
+ - lib/kindleclippings/clippingresult.rb
48
+ - lib/kindleclippings/core_ext/string.rb
49
+ - lib/kindleclippings/core_ext/symbol.rb
50
+ - lib/kindleclippings/parser.rb
48
51
  - LICENSE
49
52
  - README.markdown
50
53
  has_rdoc: true