Skip to content

Commit 0007406

Browse files
committed
Refactor generator classes
1 parent 9c3eaee commit 0007406

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

lib/ever2boost/cli.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class CLI < Thor
88
desc "import", "import from evernote"
99
def import
1010
developer_token = ask('DEVELOPER_TOKEN:')
11-
EvernoteAuthorizer.new(developer_token).generate_cson(DEFAULT_OUTPUT_DIR)
11+
EvernoteAuthorizer.new(developer_token).import(DEFAULT_OUTPUT_DIR)
1212
end
1313

1414
class << self

lib/ever2boost/cson_generator.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
module Ever2boost
22
class CsonGenerator
33
class << self
4-
def generate(folder_hash, note, output_dir)
5-
timestamp = self.timestamp
4+
def build(folder_hash, note)
65
md_note_content = MdConverter.convert(note.content)
76
cson = <<-EOS
87
type: "MARKDOWN_NOTE"
@@ -17,16 +16,18 @@ def generate(folder_hash, note, output_dir)
1716
createdAt: "#{timestamp}"
1817
updatedAt: "#{timestamp}"
1918
EOS
19+
end
20+
21+
def timestamp
22+
Time.now.strftime("%Y-%m-%dT%H:%M:%S")
23+
end
2024

25+
def output(folder_hash, note, output_dir)
2126
FileUtils.mkdir_p("#{output_dir}/notes") unless FileTest.exist?("#{output_dir}/notes")
2227
File.open("#{output_dir}/notes/#{note.file_name}.cson", "w") do |f|
23-
f.write(cson)
28+
f.write(self.build(folder_hash, note))
2429
end
2530
end
26-
27-
def timestamp
28-
"2017-01-21T14:32:48.984Z"
29-
end
3031
end
3132
end
3233
end

lib/ever2boost/evernote_authorizer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def fetch_notes(filter)
5353
def import(output_dir)
5454
FileUtils.mkdir_p(output_dir) unless FileTest.exist?(output_dir)
5555

56-
Ever2boost::JsonGenerator.generate_boostnote_json(self.notebook_list, output_dir)
56+
Ever2boost::JsonGenerator.output(self.notebook_list, output_dir)
5757

5858
self.notebook_guids.each do |notebook_guid|
5959
filter = Evernote::EDAM::NoteStore::NoteFilter.new(notebookGuid: notebook_guid)
@@ -64,7 +64,7 @@ def import(output_dir)
6464
notes.each do |note|
6565
self.notebook_list.each do |list|
6666
# TODO: break if note not found
67-
CsonGenerator.generate(list.hash, note, output_dir) if list.guid == note.notebook_guid
67+
CsonGenerator.output(list.hash, note, output_dir) if list.guid == note.notebook_guid
6868
end
6969
end
7070
end

lib/ever2boost/json_generator.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ class JsonGenerator
1111
].freeze
1212

1313
class << self
14-
def generate_boostnote_json(note_list, output_dir)
14+
def build(notebook_list)
1515
folders = <<-EOS
1616
EOS
1717

18-
note_list.each do |list|
18+
notebook_list.each do |list|
1919
random_color = self.random_color
20-
brace = note_list.last == list ? '}' : '},'
20+
brace = notebook_list.last == list ? '}' : '},'
2121
folders += <<-EOS
2222
{
2323
"key": "#{list.hash}",
@@ -35,16 +35,18 @@ def generate_boostnote_json(note_list, output_dir)
3535
"version": "1.0"
3636
}
3737
EOS
38-
39-
File.open("#{output_dir}/boostnote.json","w") do |f|
40-
f.write(json)
41-
end
4238
end
4339

4440
def random_color
4541
index = ((Random.new().rand * 7)*10.floor % 7).to_i
4642
FOLDER_COLORS[index]
4743
end
44+
45+
def output(notebook_list, output_dir)
46+
File.open("#{output_dir}/boostnote.json","w") do |f|
47+
f.write(self.build(notebook_list))
48+
end
49+
end
4850
end
4951
end
5052
end

0 commit comments

Comments
 (0)