highlights 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d2f5c225843527c05097f6994730cfe7f9ba1ebfafb5381dd46d853269e29f9b
4
+ data.tar.gz: 2667c9be6107490ca8fab2406917c5d8b44e1dc0168bf5aaf5e2fac9b0e1ca68
5
+ SHA512:
6
+ metadata.gz: dca87c203d656b54c1c0fc31653a95bfe8179e284f7bafb321d63d3dcce523d439bc06079ba55f318cf36c36f9d270bf953903c9fc3291780eff1a8a3a4f82e4
7
+ data.tar.gz: 128dd5672ec4e649bc748ca7c580e09f6e07f557e2cf3d6ee07bf146c57e996c27532fe58060ac5e56004db56d8af3bb4e1b44f8aef92d5b593d22cb937e3992
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.csv
10
+ notes.md
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in highlights.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ highlights (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (12.3.3)
10
+
11
+ PLATFORMS
12
+ x64-mingw32
13
+
14
+ DEPENDENCIES
15
+ highlights!
16
+ rake (~> 12.0)
17
+
18
+ BUNDLED WITH
19
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Graham Marlow
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # Highlights
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.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'highlights'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install highlights
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/highlights.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "highlights"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "highlights"
5
+
6
+ Highlights::CLI.new(ARGV).run
7
+
@@ -0,0 +1,26 @@
1
+ require_relative 'lib/highlights/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "highlights"
5
+ spec.version = Highlights::VERSION
6
+ spec.authors = ["Graham Marlow"]
7
+ spec.email = ["mgmarlow@hey.com"]
8
+
9
+ spec.summary = "A readable format for Kindle notes."
10
+ spec.homepage = "https://github.com/mgmarlow/highlights"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/mgmarlow/highlights"
16
+ spec.metadata["changelog_uri"] = "https://github.com/mgmarlow/highlights/blob/main/CHANGELOG.md"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+ end
@@ -0,0 +1,93 @@
1
+ require "highlights/version"
2
+ require "csv"
3
+ require "optparse"
4
+
5
+ module Highlights
6
+ class Error < StandardError; end
7
+ Note = Struct.new(:type, :location, :starred, :annotation)
8
+ 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
+ end
@@ -0,0 +1,3 @@
1
+ module Highlights
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: highlights
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Graham Marlow
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - mgmarlow@hey.com
16
+ executables:
17
+ - highlights
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - exe/highlights
30
+ - highlights.gemspec
31
+ - lib/highlights.rb
32
+ - lib/highlights/version.rb
33
+ homepage: https://github.com/mgmarlow/highlights
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ homepage_uri: https://github.com/mgmarlow/highlights
38
+ source_code_uri: https://github.com/mgmarlow/highlights
39
+ changelog_uri: https://github.com/mgmarlow/highlights/blob/main/CHANGELOG.md
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.3.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.1.2
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: A readable format for Kindle notes.
59
+ test_files: []