kindleclippings 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -5,11 +5,21 @@ Kindleclippings is a ruby library for parsing annotations created on your kindle
5
5
  When you make annotations on a kindle, they are saved as a file called "My Clippings.txt" under the documents folder.
6
6
  This library will parse these annotations/clippings and give you an array of ruby objects.
7
7
 
8
+ ## Installation
9
+
10
+ To install kindleclippings just run
11
+
12
+ % sudo gem install kindleclippings
13
+
8
14
  ## Usage
9
15
 
16
+ ### Parsing
17
+
18
+ Parsing the `My Clippings.txt` file.
19
+
10
20
  require 'kindleclippings'
11
21
 
12
- parser = KindleClippings::ClippingParser.new
22
+ parser = KindleClippings::Parser.new
13
23
 
14
24
  clippings = parser.parse_file('My Clippings.txt')
15
25
  clipping = clippings.last
@@ -18,14 +28,24 @@ This library will parse these annotations/clippings and give you an array of rub
18
28
  clipping.author # => "Berkun Scott"
19
29
  clipping.type # => :Highlight
20
30
  clipping.added_on # => #<DateTime: 2009-12-14T19:10:00+00:00 (353545963/144,0/1,2299161)>
21
- clipping.content # => "Most people say \"umm\" and \"uhh\" when they speak. These are called filler sounds, and we make them mostly to hold our place in conversation. You're letting the people you're talking to know you are not done speaking."
31
+ clipping.content # => "Most people say \"umm\" and \"uhh\" when they speak. These are called filler sounds ..."
32
+
33
+ The annotations can also be parsed directly.
22
34
 
23
- ## Note on Patches/Pull Requests
35
+ require 'kindleclippings'
36
+
37
+ parser = KindleClippings::Parser.new
38
+ clippings = parser.parse("the content you want to parse.")
39
+
40
+ ### Retrieve only the information you care about
41
+
42
+ You can retrieve only the annotationstypes you care about. After parsing, you can call `highlights`, `notes` or `bookmarks` on the collection to get only annotations of that type.
24
43
 
25
- * Fork the project.
26
- * Make your feature addition or bug fix.
27
- * Add tests for it. This is important so I don't break it in a
28
- future version unintentionally.
29
- * Commit, do not mess with rakefile, version, or history.
30
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
31
- * Send me a pull request. Bonus points for topic branches.
44
+ require 'kindleclippings'
45
+
46
+ parser = KindleClippings::Parser.new
47
+ clippings = parser.parse_file('My Clippings.txt')
48
+
49
+ clippings.notes # All the notes
50
+ clippings.highlights # All the highlights
51
+ clippings.bookmarks # All the bookmarks
@@ -0,0 +1,25 @@
1
+ module KindleClippings
2
+
3
+ class ClippingResult < Array
4
+
5
+ def highlights
6
+ filter_by_type(:Highlight)
7
+ end
8
+
9
+ def notes
10
+ filter_by_type(:Note)
11
+ end
12
+
13
+ def bookmarks
14
+ filter_by_type(:Bookmark)
15
+ end
16
+
17
+ private
18
+
19
+ def filter_by_type(type)
20
+ return self unless type
21
+ self.select { |item| item.type == type }
22
+ end
23
+
24
+ end
25
+ end
@@ -1,15 +1,15 @@
1
1
  # encoding: utf-8
2
2
  module KindleClippings
3
3
 
4
- class ClippingParser
5
- require File.expand_path(File.dirname(__FILE__) + '/clipping.rb')
4
+ class Parser
5
+ ['clipping', 'clippingresult'].each { |file| require File.expand_path(File.dirname(__FILE__) + '/' + file) }
6
6
 
7
7
  def parse_file(path)
8
8
  parse(open(path).read)
9
9
  end
10
10
 
11
11
  def parse(filecontent)
12
- @clippings = Array.new
12
+ @clippings = ClippingResult.new
13
13
 
14
14
  filecontent.split("=" * 10).each do |clipping|
15
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kindleclippings
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georg Alexander Boe
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-29 00:00:00 +01:00
12
+ date: 2010-01-09 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -33,6 +33,7 @@ extra_rdoc_files:
33
33
  - README.markdown
34
34
  files:
35
35
  - lib/clipping.rb
36
+ - lib/clippingresult.rb
36
37
  - lib/kindleclippings.rb
37
38
  - LICENSE
38
39
  - README.markdown