Skip to content

Commit 58eb0d6

Browse files
committed
Change to use json instead of here document
1 parent 41dde74 commit 58eb0d6

File tree

2 files changed

+13
-41
lines changed

2 files changed

+13
-41
lines changed

lib/ever2boost/json_generator.rb

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1+
require 'json'
2+
13
module Ever2boost
24
class JsonGenerator
35
class << self
46
def build(notebook_list)
5-
folders = <<-EOS
6-
EOS
7-
8-
notebook_list.each do |list|
9-
brace = notebook_list.last == list ? '}' : '},'
10-
folders += <<-EOS
11-
{
12-
"key": "#{list.hash}",
13-
"name": "#{list.title}",
14-
"color": "#{list.color}"
15-
#{brace}
16-
EOS
17-
end
18-
19-
json = <<-EOS
20-
{
21-
"folders": [
22-
#{folders.chomp}
23-
],
24-
"version": "1.0"
25-
}
26-
EOS
7+
{
8+
folders: notebook_list.map { |list|
9+
{
10+
key: list.hash,
11+
name: list.title,
12+
color: list.color
13+
}
14+
},
15+
version: '1.0'
16+
}.to_json
2717
end
2818

2919
def output(notebook_list, output_dir)

spec/json_generator_spec.rb

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,7 @@
44
let (:notelist1) { Ever2boost::NoteList.new(title: 'title1', guid: '012345abcdef')}
55
let (:notelist2) { Ever2boost::NoteList.new(title: 'title2', guid: '0123456abcde')}
66
let (:notebook_list) { [notelist1, notelist2] }
7-
let (:json) do
8-
<<-EOS
9-
{
10-
"folders": [
11-
{
12-
"key": "012345abcdef",
13-
"name": "title1",
14-
"color": "#E10051"
15-
},
16-
{
17-
"key": "0123456abcde",
18-
"name": "title2",
19-
"color": "#E10051"
20-
}
21-
],
22-
"version": "1.0"
23-
}
24-
EOS
25-
end
7+
let (:json) { "{\"folders\":[{\"key\":\"012345abcdef\",\"name\":\"title1\",\"color\":\"#E10051\"},{\"key\":\"0123456abcde\",\"name\":\"title2\",\"color\":\"#E10051\"}],\"version\":\"1.0\"}" }
268

279
describe '#build' do
2810
before do

0 commit comments

Comments
 (0)