highlights 1.0.0 → 1.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fcea1731a6628ecb00dbc6b494a293063e34acaf08bb9606a9ba3fed874146b
4
- data.tar.gz: fb981259fcb198c412fef78b5b0a022328513e70fe9aff5aa0a743491f19e133
3
+ metadata.gz: 832f4ea3a552923f9c87fe91567aeee0180005e58938537d252bf68385c3a24a
4
+ data.tar.gz: 54fb8e68ac68bad41d5b34ffa114ac1399e3b3c24a859666da6e326b76e7c5f3
5
5
  SHA512:
6
- metadata.gz: aeee1c45284bbfe64b6c933d0e66e407de65fd88ded8cbedaa22c95589622446d551a64a887dbbf8e5dc1a36bafe85443705bd30ce042d980c7e8540ec9d3705
7
- data.tar.gz: 9f0de9d7738dc8d1c7dea24acd865b9174c2cd12204b83b6243b8762d8e7f9bfcf5a0b4999b0afdd79c9771e3ee54aa98d37f5b47bcb6c693007f5492b7397b8
6
+ metadata.gz: 62e516c81fa1961155219428448e4053d31fa92c2e0825a598adf18d91494926cba856a9c5e4fad6c09809b772286a92ba1ca7de725d9f205c9023e62d627455
7
+ data.tar.gz: fe6bd2fbb6e83f440dc6456bce5471564f62841a6f29ff5b3a2bdd513bd91a959d9dabd0b25cbfe5f4b8a71894a6080795cc2c3342cd441e912012d03d7ece28
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- highlights (0.1.0)
4
+ highlights (1.0.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,28 +1,52 @@
1
1
  # Highlights
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/highlights`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ A CLI that converts Kindle CSV documents to Markdown.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ ## Example
6
6
 
7
- ## Installation
7
+ ```
8
+ $ highlights -f zamm_notes.csv -o zamm_notes.md
9
+ $ head zamm_notes.md
10
+ ```
8
11
 
9
- Add this line to your application's Gemfile:
12
+ Outputs:
10
13
 
11
- ```ruby
12
- gem 'highlights'
13
14
  ```
15
+ # ZEN AND THE ART OF MOTORCYCLE MAINTENANCE: AN INQUIRY INTO VALUES
16
+ ## by Robert M. Pirsig
17
+
18
+ ### Notes
14
19
 
15
- And then execute:
20
+ > You�re a passive observer and it is all moving by you boringly in a frame.
16
21
 
17
- $ bundle install
22
+ Highlight (Yellow): Page 4
18
23
 
19
- Or install it yourself as:
24
+ > Instead you spend your time being aware of things and meditating on them. On sights and sounds, on the mood of the weather and things remembered, on the machine and the countryside you�re in, thinking about things at great leisure and length without being hurried and without feeling you�re losing time.
25
+
26
+ Highlight (Yellow): Page 6
27
+ ```
28
+
29
+ ## Installation
20
30
 
21
- $ gem install highlights
31
+ ```
32
+ $ gem install highlights
33
+ ```
22
34
 
23
35
  ## Usage
24
36
 
25
- TODO: Write usage instructions here
37
+ ```
38
+ $ highlights -f zamm_notes.csv
39
+ ```
40
+
41
+ ```
42
+ $ highlights -h
43
+
44
+ Usage: highlights [options]
45
+ -f, --file=FILENAME Kindle notes CSV file
46
+ -o, --output=OUTPUT Output file (default: notes.md)
47
+ -h, --help Show help
48
+ -v, --version Show version
49
+ ```
26
50
 
27
51
  ## Development
28
52
 
@@ -32,7 +56,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
56
 
33
57
  ## Contributing
34
58
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/highlights.
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mgmarlow/highlights.
36
60
 
37
61
 
38
62
  ## License
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "bundler/setup"
4
4
  require "highlights"
5
+ require "highlights/cli"
5
6
 
6
7
  Highlights::CLI.new(ARGV).run
7
8
 
@@ -1,93 +1,12 @@
1
- require "highlights/version"
2
1
  require "csv"
3
2
  require "optparse"
4
3
 
4
+ require "highlights/error"
5
+ require "highlights/version"
6
+ require "highlights/parser"
7
+ require "highlights/renderer"
8
+
5
9
  module Highlights
6
- class Error < StandardError; end
7
10
  Note = Struct.new(:type, :location, :starred, :annotation)
8
11
  Document = Struct.new(:title, :author, :notes)
9
-
10
- class Renderer
11
- def initialize(document, outfile)
12
- @document = document
13
- @outfile = outfile
14
- end
15
-
16
- def render
17
- File.open(@outfile, 'w') do |file|
18
- file.puts("# #{@document.title}")
19
- file.puts("## #{@document.author}")
20
- file.puts("### Notes")
21
- file.write("\n")
22
-
23
- @document.notes.each do |note|
24
- file.puts("> #{note.annotation}")
25
- file.write("\n")
26
- file.puts("#{note.type}: #{note.location}")
27
- file.write("\n")
28
- end
29
- end
30
- end
31
- end
32
-
33
- class Parser
34
- class MalformedCSVError < Error; end
35
- NOTES_STARTING_POSITION = 8
36
-
37
- def initialize(filename)
38
- @filename = filename
39
- end
40
-
41
- def parse
42
- table = CSV.read(@filename, liberal_parsing: true)
43
-
44
- notes = table[NOTES_STARTING_POSITION...].map do |note_row|
45
- Note.new(*note_row)
46
- end
47
-
48
- Document.new(table[1][0], table[2][0], notes)
49
- rescue StandardError => e
50
- raise MalformedCSVError.new(e.message)
51
- end
52
- end
53
-
54
- class CLI
55
- Options = Struct.new(:filename, :output)
56
-
57
- def initialize(args)
58
- @args = args
59
- end
60
-
61
- def run
62
- options = get_options
63
- document = Parser.new(options.filename).parse
64
- Renderer.new(document, options.output).render
65
- end
66
-
67
- def get_options
68
- options = Options.new(nil, "notes.md")
69
-
70
- OptionParser.new do |opts|
71
- opts.on("-fFILENAME", "--file=FILENAME", "Kindle notes CSV file") do |f|
72
- options.filename = f
73
- end
74
-
75
- opts.on("-oOUTPUT", "--output=OUTPUT", "Output file") do |o|
76
- options.output = o
77
- end
78
-
79
- opts.on("-h", "--help", "Show help") do
80
- puts opts
81
- exit
82
- end
83
-
84
- opts.on("-v", "--version", "Show version") do
85
- puts VERSION
86
- exit
87
- end
88
- end.parse!(@args)
89
-
90
- options
91
- end
92
- end
93
12
  end
@@ -0,0 +1,41 @@
1
+ module Highlights
2
+ class CLI
3
+ Options = Struct.new(:filename, :output)
4
+
5
+ def initialize(args)
6
+ @args = args
7
+ end
8
+
9
+ def run
10
+ options = get_options
11
+ document = Parser.new(options.filename).parse
12
+ Renderer.new(document, options.output).render
13
+ end
14
+
15
+ def get_options
16
+ options = Options.new(nil, "notes.md")
17
+
18
+ OptionParser.new do |opts|
19
+ opts.on("-fFILENAME", "--file=FILENAME", "Kindle notes CSV file") do |f|
20
+ options.filename = f
21
+ end
22
+
23
+ opts.on("-oOUTPUT", "--output=OUTPUT", "Output file (default: notes.md)") do |o|
24
+ options.output = o
25
+ end
26
+
27
+ opts.on("-h", "--help", "Show help") do
28
+ puts opts
29
+ exit
30
+ end
31
+
32
+ opts.on("-v", "--version", "Show version") do
33
+ puts VERSION
34
+ exit
35
+ end
36
+ end.parse!(@args)
37
+
38
+ options
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,4 @@
1
+ module Highlights
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,22 @@
1
+ module Highlights
2
+ class Parser
3
+ class MalformedCSVError < Error; end
4
+ NOTES_STARTING_POSITION = 8
5
+
6
+ def initialize(filename)
7
+ @filename = filename
8
+ end
9
+
10
+ def parse
11
+ table = CSV.read(@filename, liberal_parsing: true)
12
+
13
+ notes = table[NOTES_STARTING_POSITION...].map do |note_row|
14
+ Note.new(*note_row)
15
+ end
16
+
17
+ Document.new(table[1][0], table[2][0], notes)
18
+ rescue StandardError => e
19
+ raise MalformedCSVError.new(e.message)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ module Highlights
2
+ class Renderer
3
+ def initialize(document, outfile)
4
+ @document = document
5
+ @outfile = outfile
6
+ end
7
+
8
+ def render
9
+ File.open(@outfile, 'w') do |file|
10
+ file.puts("# #{@document.title}")
11
+ file.puts("## #{@document.author}")
12
+ file.write("\n")
13
+ file.puts("### Notes")
14
+ file.write("\n")
15
+
16
+ @document.notes.each do |note|
17
+ file.puts("> #{note.annotation}")
18
+ file.write("\n")
19
+ file.puts("#{note.type}: #{note.location}")
20
+ file.write("\n")
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Highlights
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: highlights
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Graham Marlow
@@ -29,6 +29,10 @@ files:
29
29
  - exe/highlights
30
30
  - highlights.gemspec
31
31
  - lib/highlights.rb
32
+ - lib/highlights/cli.rb
33
+ - lib/highlights/error.rb
34
+ - lib/highlights/parser.rb
35
+ - lib/highlights/renderer.rb
32
36
  - lib/highlights/version.rb
33
37
  homepage: https://github.com/mgmarlow/highlights
34
38
  licenses: