simple_note_parser 0.1.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7fcacab485cab2f6edfe6e0aa548f9f94b22b0101051f04eaa0d10b94385068
4
- data.tar.gz: dac28c36c74d0f159e34cd022eb8c284dacee157d7a117b0731d39f6de6243a9
3
+ metadata.gz: 283d4e0a12561fbb3abd8be9f0ac7a8fe66881f323e1a1fd126e042493974410
4
+ data.tar.gz: f724c4b9a0acd1653df3404c9ca3733b53bbabf7f6dd36a64063173743077969
5
5
  SHA512:
6
- metadata.gz: 6240465534416c46d73797dd830749865eebac51c3799908d32e324fa5aa7aae40fb3f4276176aa5a9984d608b9bccfe9183ebecb6b9283fcad3930faae255bc
7
- data.tar.gz: 9d5b5eadb4a66a496662f597b148e35e105ac514e62e06e752ff839c46696c76bac034196937e981a52f7ff8b34b298904185bae61a05d9f9d06f8f9ecaf2391
6
+ metadata.gz: f7195682e205da44e01328b0aa89bf94f46ef87084f086fe6eaf0bd0e53bd5157e132b3b6f50fdc54c2ebb106a86717bef74231de5d89adef6f0abe62cd13c08
7
+ data.tar.gz: 667254781049a78e6e7389822d7154b09f0bb0f7c4621be1f43c88355a839c0c7e579ae547aedfcb50a4d37c689b759beb63999cc0f1df457856b8e3f6906104
data/.gitignore CHANGED
@@ -6,3 +6,6 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ .DS_Store
10
+ test/tmp/
11
+ .byebug_history
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.1
data/Gemfile CHANGED
@@ -5,3 +5,4 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "minitest", "~> 5.0"
8
+ gem "byebug", "~> 11.1", ">= 11.1.3"
data/Gemfile.lock CHANGED
@@ -1,11 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_note_parser (0.1.2)
4
+ simple_note_parser (2.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ byebug (11.1.3)
9
10
  minitest (5.14.0)
10
11
  rake (12.3.2)
11
12
 
@@ -13,6 +14,7 @@ PLATFORMS
13
14
  ruby
14
15
 
15
16
  DEPENDENCIES
17
+ byebug (~> 11.1, >= 11.1.3)
16
18
  minitest (~> 5.0)
17
19
  rake (~> 12.0)
18
20
  simple_note_parser!
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # SimpleNoteParser
2
2
 
3
- Organizes exported [Simplenote](https://app.simplenote.com/) data into directories based on the note's tag.
3
+ Organizes and parse exported [Simplenote](https://app.simplenote.com/) data.
4
+
5
+ - Organize notes into directories based on the note's tag.
6
+ - Merge notes into a `csv` file.
4
7
 
5
8
  ## Installation
6
9
 
@@ -23,27 +26,61 @@ Or install it yourself as:
23
26
  1. Export data from [Simplenote](https://simplenote.com/help/#export).
24
27
  1. Unzip the file.
25
28
  1. Open a new terminal window and change directories by navigating into the unzipped directory.
26
- 1. Run `gem install simple_note_parser`
27
- 1. Run `irb` to start a new Ruby session. Once the prompt starts, run the following:
29
+ 1. Run `gem install simple_note_parser`.
30
+ 1. Run `irb` to start a new Ruby session. Once the prompt starts, run `require "simple_note_parser"`.
28
31
 
29
- ```console
30
- > require "simple_note_parser"
31
- => true
32
- > @notes = SimpleNoteParser.new
33
- => #<SimpleNoteParser:0x00007fef45892768 @file="./source/notes.json", @destination="./organized-by-tag">
34
- > @notes.import
35
- => ...
32
+ Once you complete these steps, you can use `SimpleNoteParser::Organizer` or organize notes, or `SimpleNoteParser::Processor` to create a `csv` from the notes.
33
+
34
+ ### SimpleNoteParser::Organizer
35
+
36
+ Organizes notes into directories based on the note's tag.
37
+
38
+ ```ruby
39
+ SimpleNoteParser::Organizer.new(file: "./source/notes.json", destination: "./dist/organized-by-tags")
36
40
  ```
37
41
 
42
+ - Requires a `file` value. This is the `JSON` file exported by SimpleNote.
43
+ - Defaults to `./source/notes.json`.
44
+ - Requires a `destination` value. This is where the directories will be created.
45
+ - Defaults to `./dist/organized-by-tags`.
46
+
47
+ #### Usage
48
+
38
49
  This will create a directory called `organized-by-tag` in the current directory which will contain additional directories based on each note's tag.
39
50
 
40
- 1. Optionally run `@notes.clean` to recursively remove the `organized-by-tag` directory.
51
+ ```console
52
+ > @notes = SimpleNoteParser::Organizer.new
53
+ > @notes.organize_by_tag
54
+ ```
55
+
56
+ Optionally run `@notes.clean` to recursively remove the `organized-by-tag` directory.
57
+
58
+ ### SimpleNoteParser::Processor
59
+
60
+ Merge notes into a `csv` file.
61
+
62
+ ```ruby
63
+ SimpleNoteParser::Processor.new(file: "./source/notes.json", destination: "./dist", headers: %w[title content tags])
64
+ ```
65
+
66
+ - Requires a `file` value. This is the `JSON` file exported by SimpleNote.
67
+ - Defaults to `./source/notes.json`.
68
+ - Requires a `destination` value. This is where the `csv` will be created.
69
+ - Defaults to `./dist`.
70
+ - Requires a `headers` value. This will be used as the header row in the `csv`.
71
+ - Defaults to `["title", "content", "tags"]`.
72
+
73
+ #### Usage
74
+
75
+ This will create a `csv` of notes called `notes.csv` in the destination directory.
41
76
 
42
77
  ```console
43
- > @notes.clean
44
- => ["./organized-by-tag"]
78
+ > @notes = SimpleNoteParser::Processor.new
79
+ > @notes.save_as_csv
45
80
  ```
46
81
 
82
+ Optionally run `@notes.clean` to remove the destination directory and `csv`.
83
+
47
84
  ## Development
48
85
 
49
86
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -1,60 +1,3 @@
1
1
  require "simple_note_parser/version"
2
- require "json"
3
- require "fileutils"
4
- class SimpleNoteParser
5
- attr_accessor :file, :destination
6
-
7
- def initialize(file = "./source/notes.json", destination = "./organized-by-tag")
8
- @file = file
9
- @destination = destination
10
- end
11
-
12
- def clean
13
- FileUtils.rm_rf(destination)
14
- end
15
-
16
- def import
17
- json_data = load_json_data(file)
18
- notes = parse_json_data(json_data)
19
- process_notes(notes)
20
- end
21
-
22
- private
23
-
24
- def load_json_data(path)
25
- file = File.open path
26
- json_data = JSON.load file
27
- end
28
-
29
- def parse_json_data(json_data)
30
- notes = json_data["activeNotes"]
31
- end
32
-
33
- def process_notes(notes)
34
- notes.each do |note|
35
- tags = note["tags"]
36
- if tags.nil? || tags.empty?
37
- path = "#{destination}/no-tags"
38
- create_directory(path)
39
- create_file(path, note)
40
- else
41
- tags.each do |tag|
42
- path = "#{destination}/#{tag.downcase}"
43
- create_directory(path)
44
- create_file(path, note)
45
- end
46
- end
47
- end
48
- end
49
-
50
- def create_directory(path)
51
- FileUtils.mkdir_p(path) unless Dir.exist?(path)
52
- end
53
-
54
- def create_file(path, note)
55
- first_line = note["content"].split("\r").first
56
- name = first_line.downcase.strip.tr(" ", "-").gsub(/[^\w-]/, "")
57
- content = note["content"]
58
- File.open("#{path}/#{name}.txt", "w") { |f| f.write content }
59
- end
60
- end
2
+ require "simple_note_parser/organizer"
3
+ require "simple_note_parser/processor"
@@ -0,0 +1,31 @@
1
+ require "json"
2
+ require "fileutils"
3
+ module SimpleNoteParser
4
+ class Base
5
+ attr_accessor :file, :destination
6
+
7
+ def initialize(file: "./source/notes.json", destination: "./dist")
8
+ @file = file
9
+ @destination = destination
10
+ end
11
+
12
+ def clean
13
+ FileUtils.rm_rf(destination)
14
+ end
15
+
16
+ private
17
+
18
+ def load_json_data(path)
19
+ file = File.open path
20
+ JSON.load file
21
+ end
22
+
23
+ def parse_json_data(json_data)
24
+ json_data["activeNotes"]
25
+ end
26
+
27
+ def create_directory(path)
28
+ FileUtils.mkdir_p(path) unless Dir.exist?(path)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,43 @@
1
+ require "simple_note_parser/base"
2
+ module SimpleNoteParser
3
+ class Organizer < SimpleNoteParser::Base
4
+ attr_accessor :file, :destination
5
+
6
+ def initialize(file: "./source/notes.json", destination: "./dist/organized-by-tags")
7
+ @file = file
8
+ @destination = destination
9
+ end
10
+
11
+ def organize_by_tag
12
+ json_data = load_json_data(file)
13
+ notes = parse_json_data(json_data)
14
+ process_notes(notes)
15
+ end
16
+
17
+ private
18
+
19
+ def process_notes(notes)
20
+ notes.each do |note|
21
+ tags = note["tags"]
22
+ if tags.nil? || tags.empty?
23
+ path = "#{destination}/no-tags"
24
+ create_directory(path)
25
+ create_file(path, note)
26
+ else
27
+ tags.each do |tag|
28
+ path = "#{destination}/#{tag.downcase}"
29
+ create_directory(path)
30
+ create_file(path, note)
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ def create_file(path, note)
37
+ first_line = note["content"].split("\r").first
38
+ name = first_line.downcase.strip.tr(" ", "-").gsub(/[^\w-]/, "")
39
+ content = note["content"]
40
+ File.open("#{path}/#{name}.txt", "w") { |f| f.write content }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,50 @@
1
+ require "simple_note_parser/base"
2
+ require "csv"
3
+
4
+ module SimpleNoteParser
5
+ class Processor < SimpleNoteParser::Base
6
+ attr_accessor :file, :destination, :headers
7
+
8
+ def initialize(file: "./source/notes.json", destination: "./dist", headers: %w[title content tags])
9
+ @file = file
10
+ @destination = destination
11
+ @headers = headers
12
+ end
13
+
14
+ def save_as_csv
15
+ json_data = load_json_data(file)
16
+ notes = parse_json_data(json_data)
17
+ create_directory(destination)
18
+ create_csv
19
+ process_notes(notes)
20
+ end
21
+
22
+ private
23
+
24
+ def csv_path
25
+ destination + "/notes.csv"
26
+ end
27
+
28
+ def process_notes(notes)
29
+ CSV.open(csv_path, "wb", headers: true) do |csv|
30
+ csv << headers
31
+ notes.each do |note|
32
+ add_row_to_csv(note, csv)
33
+ end
34
+ end
35
+ end
36
+
37
+ def add_row_to_csv(note, csv)
38
+ title = note["content"].split("\r").first
39
+ content = note["content"]
40
+ tags = note["tags"]
41
+ formatted_tags = tags.join(", ") unless tags.nil?
42
+ csv << [title, content, formatted_tags]
43
+ end
44
+
45
+ def create_csv
46
+ CSV.new(csv_path, headers: true)
47
+ end
48
+
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
- class SimpleNoteParser
2
- VERSION = "0.1.2"
1
+ module SimpleNoteParser
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_note_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Polito
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-08 00:00:00.000000000 Z
11
+ date: 2020-05-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Organizes exported Simplenote data into directories based on the note's
14
14
  tag.
@@ -19,6 +19,7 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - ".gitignore"
22
+ - ".ruby-version"
22
23
  - ".travis.yml"
23
24
  - Gemfile
24
25
  - Gemfile.lock
@@ -28,6 +29,9 @@ files:
28
29
  - bin/console
29
30
  - bin/setup
30
31
  - lib/simple_note_parser.rb
32
+ - lib/simple_note_parser/base.rb
33
+ - lib/simple_note_parser/organizer.rb
34
+ - lib/simple_note_parser/processor.rb
31
35
  - lib/simple_note_parser/version.rb
32
36
  - simple_note_parser.gemspec
33
37
  homepage: https://github.com/stevepolitodesign/simple_note_parser
@@ -52,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
56
  - !ruby/object:Gem::Version
53
57
  version: '0'
54
58
  requirements: []
55
- rubygems_version: 3.0.8
59
+ rubygems_version: 3.1.2
56
60
  signing_key:
57
61
  specification_version: 4
58
62
  summary: Parse notes from Simplenote