pnote_client 1.2.3 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/pnote_to_json +31 -5
- data/lib/pnote_client/converters/hml_to_pnote_converter.rb +11 -7
- data/lib/pnote_client/converters/pnote_to_json_converter.rb +25 -25
- data/lib/pnote_client/documents/pnote/chapter.rb +2 -2
- data/lib/pnote_client/documents/pnote/concept.rb +1 -1
- data/lib/pnote_client/documents/pnote/problem.rb +17 -7
- data/lib/pnote_client/documents/pnote/sub_chapter.rb +2 -2
- data/lib/pnote_client/documents/pnote/teacher_comment.rb +4 -4
- data/lib/pnote_client/version.rb +1 -1
- metadata +2 -4
- data/lib/pnote_client/documents/pnote/exercise.rb +0 -10
- data/lib/pnote_client/documents/pnote/practice.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6768e747c37505e8606dd774b8ff50bed95eaa2c76673aa6ab26ad39a640f7f5
|
4
|
+
data.tar.gz: 87eee8422ea2646fbe047558f4839915c5128258a87fd5c4ab305db9fa51d516
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6cede281e8d80463854ee8beb831b675b262de076393ec39458c21d053f8fbe2e66c323cd1858ba25888d77a7bca9c6709f671d3558ac0d772d54048e9163ee
|
7
|
+
data.tar.gz: 30a5fe6cc5bdda30450e4dbd94c3641c6d93847de1d871491a8a7c6ef0bcc58d3a6fc4ceb2308036857c5a36756e985baea7eae8954dc4fce702c7896bb12eea
|
data/exe/pnote_to_json
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
require 'json'
|
5
5
|
require 'optparse'
|
6
|
+
require 'pnote_client'
|
6
7
|
require 'pnote_client/converters/hml_to_pnote_converter'
|
7
8
|
require 'pnote_client/converters/pnote_to_json_converter'
|
8
9
|
require 'pnote_client/documents/hml'
|
@@ -22,7 +23,9 @@ def write_file(content, filepath)
|
|
22
23
|
end
|
23
24
|
|
24
25
|
options = {
|
25
|
-
|
26
|
+
config_filepath: File.join(File.dirname(__FILE__), '..', 'config.json'),
|
27
|
+
include_image_data: false,
|
28
|
+
show_time: 600
|
26
29
|
}
|
27
30
|
|
28
31
|
optparser = OptionParser.new do |opt|
|
@@ -43,6 +46,10 @@ optparser = OptionParser.new do |opt|
|
|
43
46
|
opt.on('-c', '--config [FILEPATH]', String, 'File path of configuration file(`config.json`). Default is `../config.json`') do |filepath|
|
44
47
|
options[:config_filepath]
|
45
48
|
end
|
49
|
+
|
50
|
+
opt.on('-t', '--time [TIME]', String, '선생님 코멘트 노출시간을 입력해주세요. 기본값 600') do |show_time|
|
51
|
+
options[:show_time] = show_time.to_i
|
52
|
+
end
|
46
53
|
end
|
47
54
|
optparser.parse!
|
48
55
|
|
@@ -50,15 +57,34 @@ if options[:input_filepath].nil? || options[:output_filepath].nil?
|
|
50
57
|
abort(optparser.help)
|
51
58
|
end
|
52
59
|
|
60
|
+
notice = <<-NOTICE
|
61
|
+
[PnoteClient Version]
|
62
|
+
#{PnoteClient::VERSION}
|
63
|
+
|
64
|
+
[변환설정]
|
65
|
+
입력파일 경로: #{options[:input_filepath]}
|
66
|
+
출력파일 경로: #{options[:output_filepath]}
|
67
|
+
이미지: #{options[:include_image_data] ? '포함' : '제외'}
|
68
|
+
설정파일 경로: #{options[:config_filepath]}
|
69
|
+
코멘트 노출시간 단위: #{options[:show_time]}초
|
70
|
+
|
71
|
+
계속 진행하시겠습니까? (y/n)
|
72
|
+
NOTICE
|
73
|
+
puts notice
|
74
|
+
response = gets.chomp.downcase
|
75
|
+
|
76
|
+
if response != 'y'
|
77
|
+
abort
|
78
|
+
end
|
79
|
+
|
53
80
|
display = PnoteClient::ConsoleDisplay.new
|
54
|
-
|
55
|
-
config_content = read_file(options[:config_filepath] || default_config_file_path)
|
81
|
+
config_content = read_file(options[:config_filepath])
|
56
82
|
config = JSON.parse(config_content, symbolize_names: true)
|
57
83
|
type_style_mapper = config[:hml_pnote_styles]
|
58
84
|
|
59
85
|
hml_document = PnoteClient::Documents::Hml.parse_from_file(options[:input_filepath])
|
60
|
-
hml_to_pnote_converter = PnoteClient::Converters::HmlToPnoteConverter.new(hml_document, type_style_mapper)
|
86
|
+
hml_to_pnote_converter = PnoteClient::Converters::HmlToPnoteConverter.new(hml_document, show_time: options[:show_time], type_style_mapper: type_style_mapper, include_image_data: options[:include_image_data])
|
61
87
|
hml_to_pnote_converter.delegate = display
|
62
88
|
pnote_document = hml_to_pnote_converter.convert
|
63
|
-
json = PnoteClient::Converters::PnoteToJsonConverter.new(pnote_document
|
89
|
+
json = PnoteClient::Converters::PnoteToJsonConverter.new(pnote_document).convert
|
64
90
|
write_file(json, options[:output_filepath])
|
@@ -2,8 +2,7 @@ require 'pnote_client/documents/pnote'
|
|
2
2
|
require 'pnote_client/documents/pnote/chapter'
|
3
3
|
require 'pnote_client/documents/pnote/sub_chapter'
|
4
4
|
require 'pnote_client/documents/pnote/concept'
|
5
|
-
require 'pnote_client/documents/pnote/
|
6
|
-
require 'pnote_client/documents/pnote/practice'
|
5
|
+
require 'pnote_client/documents/pnote/problem'
|
7
6
|
require 'pnote_client/documents/pnote/image'
|
8
7
|
require 'pnote_client/documents/pnote/teacher_comment'
|
9
8
|
require 'pnote_client/documents/hml/paragraph_reader'
|
@@ -14,9 +13,11 @@ module PnoteClient
|
|
14
13
|
|
15
14
|
attr_accessor :delegate
|
16
15
|
|
17
|
-
def initialize(hml_document, type_style_mapper
|
16
|
+
def initialize(hml_document, show_time:, type_style_mapper: {}, include_image_data: false)
|
18
17
|
@hml_document = hml_document
|
18
|
+
@show_time = show_time
|
19
19
|
@type_style_mapper = type_style_mapper
|
20
|
+
@include_image_data = include_image_data
|
20
21
|
|
21
22
|
@current_chapter = nil
|
22
23
|
@current_sub_chapter = nil
|
@@ -54,7 +55,7 @@ module PnoteClient
|
|
54
55
|
if is_continuous
|
55
56
|
@current_exercise.add_question_line(paragraph.content) if @current_exercise
|
56
57
|
else
|
57
|
-
new_exercise = Documents::Pnote::
|
58
|
+
new_exercise = Documents::Pnote::Problem.new
|
58
59
|
new_exercise.question = paragraph.content
|
59
60
|
add_new_exercise_to_sub_chapter(@current_sub_chapter, new_exercise) if @current_sub_chapter
|
60
61
|
end
|
@@ -68,7 +69,7 @@ module PnoteClient
|
|
68
69
|
if @practice_continuous
|
69
70
|
@current_practice.add_question_line(paragraph.content) if @current_practice
|
70
71
|
else
|
71
|
-
new_practice = Documents::Pnote::
|
72
|
+
new_practice = Documents::Pnote::Problem.new
|
72
73
|
new_practice.question = paragraph.content
|
73
74
|
|
74
75
|
if @current_sub_chapter
|
@@ -101,7 +102,7 @@ module PnoteClient
|
|
101
102
|
if is_continuous
|
102
103
|
@current_teacher_comment.add_content_line(footnote_paragraph.content) if @current_teacher_comment
|
103
104
|
else
|
104
|
-
new_teacher_comment = Documents::Pnote::TeacherComment.new(index)
|
105
|
+
new_teacher_comment = Documents::Pnote::TeacherComment.new(show_time: (index + 1) * @show_time)
|
105
106
|
new_teacher_comment.content = footnote_paragraph.content
|
106
107
|
add_new_teacher_comment_to_practice(@current_practice, new_teacher_comment) if @current_practice
|
107
108
|
end
|
@@ -121,7 +122,10 @@ module PnoteClient
|
|
121
122
|
|
122
123
|
binary_count = @hml_document.bin_items.length
|
123
124
|
@hml_document.bin_items.each_with_index do |bin_item, index|
|
124
|
-
|
125
|
+
raw_data = @include_image_data ? bin_item.raw_data : nil
|
126
|
+
pnote_document.add_image(
|
127
|
+
Documents::Pnote::Image.new(bin_item.id, bin_item.format, bin_item.size, raw_data)
|
128
|
+
)
|
125
129
|
|
126
130
|
@delegate.binary_converted(count: binary_count, current: index) if @delegate
|
127
131
|
end
|
@@ -1,16 +1,17 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'pnote_client'
|
2
3
|
|
3
4
|
module PnoteClient
|
4
5
|
module Converters
|
5
6
|
class PnoteToJsonConverter
|
6
7
|
|
7
|
-
def initialize(pnote_document
|
8
|
+
def initialize(pnote_document)
|
8
9
|
@pnote_document = pnote_document
|
9
|
-
@include_image_data = include_image_data
|
10
10
|
end
|
11
11
|
|
12
12
|
def convert
|
13
13
|
result = {
|
14
|
+
pnote_client_version: PnoteClient::VERSION,
|
14
15
|
chapters: [],
|
15
16
|
images: [],
|
16
17
|
created_at: Time.now.strftime("%Y-%m-%d %H:%M")
|
@@ -21,7 +22,7 @@ module PnoteClient
|
|
21
22
|
id: image.id,
|
22
23
|
format: image.format,
|
23
24
|
size: image.size,
|
24
|
-
raw_data:
|
25
|
+
raw_data: image.raw_data
|
25
26
|
}
|
26
27
|
end
|
27
28
|
|
@@ -42,14 +43,7 @@ module PnoteClient
|
|
42
43
|
|
43
44
|
# 심화단원의 실전 문제
|
44
45
|
chapter.practices.each do |practice|
|
45
|
-
practice_hash =
|
46
|
-
question: practice.question,
|
47
|
-
answer: practice.answer,
|
48
|
-
explaination: practice.explaination,
|
49
|
-
teacher_comments: practice.teacher_comments.sort_by {|tc| tc.index }.map(&:content),
|
50
|
-
choices: practice.choices,
|
51
|
-
tip: practice.tip
|
52
|
-
}
|
46
|
+
practice_hash = get_problem_hash(practice)
|
53
47
|
sub_chapter_hash[:practices] << practice_hash
|
54
48
|
end
|
55
49
|
else # 일반 단원일경우 소단원 채우기
|
@@ -72,24 +66,12 @@ module PnoteClient
|
|
72
66
|
end
|
73
67
|
|
74
68
|
sub_chapter.exercises.each do |exercise|
|
75
|
-
exercise_hash =
|
76
|
-
question: exercise.question,
|
77
|
-
answer: exercise.answer,
|
78
|
-
explaination: exercise.explaination,
|
79
|
-
choices: exercise.choices
|
80
|
-
}
|
69
|
+
exercise_hash = get_problem_hash(exercise)
|
81
70
|
sub_chapter_hash[:exercises] << exercise_hash
|
82
71
|
end
|
83
72
|
|
84
73
|
sub_chapter.practices.each do |practice|
|
85
|
-
practice_hash =
|
86
|
-
question: practice.question,
|
87
|
-
answer: practice.answer,
|
88
|
-
explaination: practice.explaination,
|
89
|
-
teacher_comments: practice.teacher_comments.sort_by {|tc| tc.index }.map(&:content),
|
90
|
-
choices: practice.choices,
|
91
|
-
tip: practice.tip
|
92
|
-
}
|
74
|
+
practice_hash = get_problem_hash(practice)
|
93
75
|
sub_chapter_hash[:practices] << practice_hash
|
94
76
|
end
|
95
77
|
end
|
@@ -98,6 +80,24 @@ module PnoteClient
|
|
98
80
|
|
99
81
|
return result.to_json
|
100
82
|
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def get_problem_hash(problem)
|
87
|
+
{
|
88
|
+
question: problem.question,
|
89
|
+
answer: problem.answer,
|
90
|
+
explaination: problem.explaination,
|
91
|
+
teacher_comments: problem.teacher_comments.sort_by {|tc| tc.show_time }.map do |tc|
|
92
|
+
{
|
93
|
+
show_time: tc.show_time,
|
94
|
+
content: tc.content
|
95
|
+
}
|
96
|
+
end,
|
97
|
+
choices: problem.choices,
|
98
|
+
tip: problem.tip
|
99
|
+
}
|
100
|
+
end
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
@@ -3,18 +3,19 @@ require 'pnote_client/utils/string_util'
|
|
3
3
|
module PnoteClient
|
4
4
|
module Documents
|
5
5
|
class Pnote
|
6
|
-
# 연습문제(Exercise)와 실전문제(Practice)의 부모 클래스
|
7
|
-
# 중복되는 부분을 재사용하기위해 만듦
|
8
6
|
class Problem
|
9
7
|
include Utils::StringUtil
|
10
8
|
|
11
9
|
attr_accessor :question, :explaination
|
10
|
+
attr_accessor :teacher_comments, :tip
|
12
11
|
|
13
|
-
def initialize
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
def initialize(
|
13
|
+
question: nil, answer: nil, explaination: nil,
|
14
|
+
choices: nil, choice: nil, teacher_comments: [], tip: nil
|
15
|
+
)
|
16
|
+
|
17
|
+
@question, @answer, @explaination, @choices, @choice, @teacher_comments, @tip =
|
18
|
+
question, answer, explaination, choices, choice, teacher_comments, tip
|
18
19
|
end
|
19
20
|
|
20
21
|
def add_question_line(new_line)
|
@@ -39,11 +40,20 @@ module PnoteClient
|
|
39
40
|
end
|
40
41
|
|
41
42
|
def choices
|
43
|
+
return @choices if @choices
|
42
44
|
return [] if @choice.nil?
|
43
45
|
|
44
46
|
choice_number_pattern = /①|②|③|④|⑤/
|
45
47
|
return @choice.split(choice_number_pattern).reject {|el| el.empty?}.map {|el| el.strip}
|
46
48
|
end
|
49
|
+
|
50
|
+
def add_teacher_comment(new_teacher_comment)
|
51
|
+
@teacher_comments << new_teacher_comment
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_tip_line(new_line)
|
55
|
+
@tip = add_line(@tip, new_line)
|
56
|
+
end
|
47
57
|
end
|
48
58
|
end
|
49
59
|
end
|
@@ -6,11 +6,11 @@ module PnoteClient
|
|
6
6
|
class TeacherComment
|
7
7
|
include Utils::StringUtil
|
8
8
|
|
9
|
-
attr_accessor :
|
9
|
+
attr_accessor :content, :show_time
|
10
10
|
|
11
|
-
def initialize(
|
12
|
-
@
|
13
|
-
@content =
|
11
|
+
def initialize(content: nil, show_time: 0)
|
12
|
+
@show_time = show_time
|
13
|
+
@content = content
|
14
14
|
end
|
15
15
|
|
16
16
|
def add_content_line(new_line)
|
data/lib/pnote_client/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pnote_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bluesh55
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -118,9 +118,7 @@ files:
|
|
118
118
|
- lib/pnote_client/documents/pnote.rb
|
119
119
|
- lib/pnote_client/documents/pnote/chapter.rb
|
120
120
|
- lib/pnote_client/documents/pnote/concept.rb
|
121
|
-
- lib/pnote_client/documents/pnote/exercise.rb
|
122
121
|
- lib/pnote_client/documents/pnote/image.rb
|
123
|
-
- lib/pnote_client/documents/pnote/practice.rb
|
124
122
|
- lib/pnote_client/documents/pnote/problem.rb
|
125
123
|
- lib/pnote_client/documents/pnote/sub_chapter.rb
|
126
124
|
- lib/pnote_client/documents/pnote/teacher_comment.rb
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'pnote_client/documents/pnote/problem'
|
2
|
-
|
3
|
-
module PnoteClient
|
4
|
-
module Documents
|
5
|
-
class Pnote
|
6
|
-
class Practice < Problem
|
7
|
-
attr_accessor :teacher_comments, :tip
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
super
|
11
|
-
@teacher_comments = []
|
12
|
-
@tip = nil
|
13
|
-
end
|
14
|
-
|
15
|
-
def add_teacher_comment(new_teacher_comment)
|
16
|
-
@teacher_comments << new_teacher_comment
|
17
|
-
end
|
18
|
-
|
19
|
-
def add_tip_line(new_line)
|
20
|
-
@tip = add_line(@tip, new_line)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|