pnote_client 2.5.0 → 2.6.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: a3ba1826c4b23e1951591e2b88f0b835ea3c5ffa2c3501f58afd971d8a0b52c2
4
- data.tar.gz: b18197526f4a93f7910310b885479c55d8f32f4c4b3b7cb3165afa54ef13cfb0
3
+ metadata.gz: 0bb3d199f3908b91924336552bc96b99bf2347bfe3d6f74502296e77279f119d
4
+ data.tar.gz: 796d96999b57c8e096fcbd894a8591f88f6b25c30baebc21ecb961873a56855b
5
5
  SHA512:
6
- metadata.gz: 1c3edfc027d91c5738e144885f03d495f87f401cbdd0c5cc31d2be566479c241520c73a3d410b1269ec62b9b3f31710d202dd26ad9f39287761a3fd5fefe3c5d
7
- data.tar.gz: 9feceda15a01f1fe44c87875057b2c85625a52bdd67bb1cd588cbfcaaf94656d10501714f5fae5a490d09a90a73ca1b152750929f5a136701edfab2782ac04a9
6
+ metadata.gz: faded062961626e6a1391f677b3f0b641e2218310ae3176539a0cc5abd34c944435bc3fe25130b7a8961b473528dffec1a230cb9ebbd827b7d34ddfef73fbf5a
7
+ data.tar.gz: d4258855df9b53d4a1737194958e3772a3fb7fc9401c6e9032b328fc249d20838b7a8364ca93faf9b0dc4a6b05ad100228f2849f867b3c21622124ce7facf57b
data/exe/pnote_to_json CHANGED
@@ -26,18 +26,13 @@ def write_file(content, filepath)
26
26
  f.close
27
27
  end
28
28
 
29
- def save_validation_log_file(hml_validate_result, pnote_validate_result, log_filepath)
29
+ def save_validation_log_file(hml_errors, pnote_errors, log_filepath)
30
30
  log_content = ""
31
- log_content += "==========[Warnings]=========="
32
- log_content += "\n"
33
- (hml_validate_result[:warnings] + pnote_validate_result[:warnings]).each_with_index do |warning, index|
34
- log_content += "#{index + 1}.\n[경고 메시지]\n#{warning[:message]}\n[상세내용]\n#{warning[:detail]}\n\n\n"
35
- end
36
- log_content += "\n\n"
37
31
  log_content += "==========[Errors]=========="
38
32
  log_content += "\n"
39
- (hml_validate_result[:errors] + pnote_validate_result[:errors]).each_with_index do |error, index|
40
- log_content += "#{index + 1}.\n[에러 메시지]\n#{error[:message]}\n[상세내용]\n#{error[:detail]}\n\n\n"
33
+ (hml_errors + pnote_errors).each_with_index do |error, index|
34
+ log_content += error
35
+ log_content += "\n\n"
41
36
  end
42
37
 
43
38
  write_file(log_content, log_filepath)
@@ -45,7 +40,6 @@ end
45
40
 
46
41
  # 커맨드라인 argument로 옵션 입력받기
47
42
  options = {
48
- config_filepath: File.join(File.dirname(__FILE__), '..', 'config.json'),
49
43
  include_image_data: false,
50
44
  show_time: 600
51
45
  }
@@ -61,10 +55,6 @@ optparser = OptionParser.new do |opt|
61
55
  options[:include_image_data] = flag
62
56
  end
63
57
 
64
- opt.on('-c', '--config [FILEPATH]', String, 'File path of configuration file(`config.json`). Default is `../config.json`') do |filepath|
65
- options[:config_filepath]
66
- end
67
-
68
58
  opt.on('-t', '--time [TIME]', String, '선생님 코멘트 노출시간을 입력해주세요. 기본값 600') do |show_time|
69
59
  options[:show_time] = show_time.to_i
70
60
  end
@@ -83,7 +73,6 @@ notice = <<-NOTICE
83
73
  [변환설정]
84
74
  입력파일 경로: #{options[:input_filepath]}
85
75
  이미지: #{options[:include_image_data] ? '포함' : '제외'}
86
- 설정파일 경로: #{options[:config_filepath]}
87
76
  코멘트 노출시간 단위: #{options[:show_time]}초
88
77
 
89
78
  계속 진행하시겠습니까? (y/n)
@@ -97,9 +86,6 @@ end
97
86
 
98
87
  # 변환 준비 작업
99
88
  display = PnoteClient::ConsoleDisplay.new
100
- _, _, config_content = read_file(options[:config_filepath])
101
- config = JSON.parse(config_content, symbolize_names: true)
102
- type_style_mapper = config[:hml_pnote_styles]
103
89
  input_filename, input_dir_path, hml_content = read_file(options[:input_filepath])
104
90
  output_filepath = File.join(input_dir_path, input_filename + ".json")
105
91
  log_filepath = File.join(input_dir_path, input_filename + ".log")
@@ -113,13 +99,13 @@ puts ""
113
99
  sleep(1)
114
100
  hml_document = PnoteClient::Documents::Hml.parse(hml_content)
115
101
  hml_validator = PnoteClient::Validators::HmlValidator.new(hml_document)
116
- hml_validate_result = hml_validator.validate
102
+ hml_errors = hml_validator.validate
117
103
 
118
104
  # HmlDocument를 PnoteDocument로 변환
119
105
  puts ""
120
106
  puts "=============================================="
121
107
  puts "hml 파일을 pnote 파일로 변환하는 중입니다..."
122
- 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])
108
+ hml_to_pnote_converter = PnoteClient::Converters::HmlToPnoteConverter.new(hml_document, show_time: options[:show_time], include_image_data: options[:include_image_data])
123
109
  hml_to_pnote_converter.delegate = display
124
110
  pnote_document = hml_to_pnote_converter.convert
125
111
  puts "=============================================="
@@ -133,7 +119,7 @@ puts "=============================================="
133
119
  puts ""
134
120
  sleep(1)
135
121
  pnote_validator = PnoteClient::Validators::PnoteValidator.new(pnote_document)
136
- pnote_validate_result = pnote_validator.validate
122
+ pnote_errors = pnote_validator.validate
137
123
 
138
124
 
139
125
  # PnoteDocument를 JSON 파일로 저장
@@ -155,13 +141,14 @@ puts "파일 경로: #{log_filepath}"
155
141
  puts "=============================================="
156
142
  puts ""
157
143
  sleep(1)
158
- save_validation_log_file(hml_validate_result, pnote_validate_result, log_filepath)
144
+ save_validation_log_file(hml_errors, pnote_errors, log_filepath)
159
145
 
160
146
  puts ""
161
147
  puts "=============================================="
162
148
  puts "변환이 완료되었습니다. (파일 경로: #{output_filepath})"
163
- puts "hml 파일 검사 결과: 경고 #{hml_validate_result[:warnings].length}개, 에러 #{hml_validate_result[:errors].length}개"
164
- puts "pnote 파일 검사 결과: 경고 #{pnote_validate_result[:warnings].length}개, 에러 #{pnote_validate_result[:errors].length}개"
149
+ puts "예제 #{pnote_document.exercise_count}개, 문제 #{pnote_document.practice_count}개"
150
+ puts "hml 파일 검사 결과: 에러 #{hml_errors.length}개"
151
+ puts "pnote 파일 검사 결과: 에러 #{pnote_errors.length}개"
165
152
  puts ""
166
153
  puts "에러가 있을 경우 json 파일 업로드나 LaTeX 렌더링에 문제가 발생할 수 있습니다."
167
154
  puts "=============================================="
@@ -1,3 +1,4 @@
1
+ require 'pnote_client'
1
2
  require 'pnote_client/documents/pnote'
2
3
  require 'pnote_client/documents/pnote/chapter'
3
4
  require 'pnote_client/documents/pnote/sub_chapter'
@@ -13,10 +14,9 @@ module PnoteClient
13
14
 
14
15
  attr_accessor :delegate
15
16
 
16
- def initialize(hml_document, show_time:, type_style_mapper: {}, include_image_data: false)
17
+ def initialize(hml_document, show_time:, include_image_data: false)
17
18
  @hml_document = hml_document
18
19
  @show_time = show_time
19
- @type_style_mapper = type_style_mapper
20
20
  @include_image_data = include_image_data
21
21
 
22
22
  @current_chapter = nil
@@ -187,7 +187,7 @@ module PnoteClient
187
187
 
188
188
  def paragraph_type(paragraph)
189
189
  pg_style = find_style(paragraph.style_id)
190
- result = @type_style_mapper.find {|k, v| v == pg_style.name || (v.is_a?(Array) && v.include?(pg_style.name))}
190
+ result = ::PnoteClient::STYLES.find {|k, v| v == pg_style.name || (v.is_a?(Array) && v.include?(pg_style.name))}
191
191
  return nil if result.nil?
192
192
  return result[0]
193
193
  end
@@ -1,4 +1,5 @@
1
1
  require 'hwp_script_to_latex/converter'
2
+ require 'hwp_script_to_latex/validator'
2
3
 
3
4
  module PnoteClient
4
5
  module Documents
@@ -15,6 +16,7 @@ module PnoteClient
15
16
 
16
17
  def initialize(script)
17
18
  @script = script
19
+ @script_validator = HwpScriptToLatex::Validator.new
18
20
  @script_converter = ::HwpScriptToLatex::Converter.new
19
21
  end
20
22
 
@@ -29,6 +31,10 @@ module PnoteClient
29
31
  def textable?
30
32
  return true
31
33
  end
34
+
35
+ def validate
36
+ return @script_validator.validate(@script)
37
+ end
32
38
  end
33
39
  end
34
40
  end
@@ -15,6 +15,22 @@ module PnoteClient
15
15
  def add_image(new_image)
16
16
  @images << new_image
17
17
  end
18
+
19
+ def exercise_count
20
+ return @chapters.sum do |chapter|
21
+ chapter.sub_chapters.sum do |sub_chapter|
22
+ sub_chapter.exercises.count
23
+ end
24
+ end
25
+ end
26
+
27
+ def practice_count
28
+ return @chapters.sum do |chapter|
29
+ chapter.sub_chapters.sum do |sub_chapter|
30
+ sub_chapter.practices.count
31
+ end
32
+ end
33
+ end
18
34
  end
19
35
  end
20
36
  end
@@ -3,107 +3,72 @@
3
3
  # Created: 2019-05-23
4
4
  # Last modified: 2019-05-23
5
5
 
6
+ require 'pnote_client'
7
+ require 'pnote_client/validators/validator'
6
8
  require 'pnote_client/documents/hml/equation'
7
9
 
8
10
  module PnoteClient
9
11
  module Validators
10
- class HmlValidator
12
+ class HmlValidator < Validator
11
13
  def initialize(hml_document)
14
+ super()
12
15
  @hml_document = hml_document
13
- @result = {
14
- errors: [],
15
- warnings: []
16
- }
17
16
  end
18
17
 
19
18
  def validate
20
- reset_result
19
+ reset_errors
21
20
  validate_document
22
- return @result
23
- end
24
-
25
- def has_error?
26
- return error_count > 0
27
- end
28
-
29
- def has_warning?
30
- return warning_count > 0
31
- end
32
-
33
- def error_count
34
- return @result[:errors].length
35
- end
36
-
37
- def warning_count
38
- return @result[:warnings].length
21
+ return @errors
39
22
  end
40
23
 
41
24
  private
42
25
 
43
- def reset_result
44
- @result = {
45
- errors: [],
46
- warnings: []
47
- }
48
- end
49
-
50
26
  def validate_document
27
+ practice_number = 1
28
+
51
29
  @hml_document.paragraphs.each do |paragraph|
52
- validate_paragraph(paragraph)
30
+ next if paragraph.style_id != practice_style_id
31
+ validate_paragraph(paragraph, practice_number)
32
+
33
+ paragraph.endnote_paragraphs.each do |paragraph|
34
+ validate_paragraph(paragraph, practice_number)
35
+ end
53
36
 
54
37
  paragraph.footnote_paragraphs.each do |paragraph|
55
- validate_paragraph(paragraph)
38
+ validate_paragraph(paragraph, practice_number)
56
39
  end
57
40
 
58
- paragraph.endnote_paragraphs.each do |paragraph|
59
- validate_paragraph(paragraph)
41
+ # 문제가 두 문단 이상으로 나눠진경우
42
+ # 풋노트 존재여부로 문제 완료 여부를 알 수 있음
43
+ if paragraph.footnote_paragraphs.length > 0
44
+ practice_number += 1
60
45
  end
61
46
  end
62
47
  end
63
48
 
64
- def validate_paragraph(paragraph)
49
+ def validate_paragraph(paragraph, practice_number)
65
50
  paragraph.elements.each do |element|
66
51
  if element.class == Documents::Hml::Equation
67
- invalids = validate_equation(element)
68
- invalids.each do |invalid|
69
- if invalid[:type] == :error
70
- @result[:errors] << {
71
- message: invalid[:message],
72
- detail: paragraph.content
73
- }
74
- elsif invalid[:type] == :warning
75
- @result[:warnings] << {
76
- message: invalid[:message],
77
- detail: paragraph.content
78
- }
79
- end
52
+ element.validate.each do |error|
53
+ add_error(
54
+ make_error(
55
+ title: error[:message],
56
+ problem_number: practice_number,
57
+ type: paragraph_style_name(paragraph),
58
+ detail: error[:detail]
59
+ )
60
+ )
80
61
  end
81
62
  end
82
63
  end
83
64
  end
84
65
 
85
- def validate_equation(equation)
86
- open_bracket_regex = /(?<![\\])\s*{/
87
- close_bracket_regex = /(?<![\\])\s*}/
88
- open_bracket_count = equation.script.scan(open_bracket_regex).length
89
- close_bracket_count = equation.script.scan(close_bracket_regex).length
90
- invalids = []
91
-
92
- if open_bracket_count > close_bracket_count
93
- invalids << {
94
- type: :error,
95
- message: "닫는 중괄호(`}`)가 부족합니다."
96
- }
97
- end
98
-
99
- if open_bracket_count < close_bracket_count
100
- invalids << {
101
- type: :error,
102
- message: "여는 중괄호(`}`)가 부족합니다."
103
- }
104
- end
66
+ def practice_style_id
67
+ @practice_style_id ||= @hml_document.styles.find {|style| style.name == PnoteClient::STYLES[:practice_question] }&.id
68
+ end
105
69
 
106
- return invalids
70
+ def paragraph_style_name(paragraph)
71
+ return @hml_document.styles.find {|style| style.id == paragraph.style_id }&.name
107
72
  end
108
73
  end
109
74
  end
@@ -2,111 +2,55 @@
2
2
  # Author: osh
3
3
  # Created: 2019-05-20
4
4
  # Last modified: 2019-05-20
5
+ require 'pnote_client/validators/validator'
5
6
 
6
7
  module PnoteClient
7
8
  module Validators
8
- class PnoteValidator
9
+ class PnoteValidator < Validator
9
10
  def initialize(pnote_document)
11
+ super()
10
12
  @pnote_document = pnote_document
11
- @result = {
12
- errors: [],
13
- warnings: []
14
- }
15
13
  end
16
14
 
17
15
  def validate
18
- reset_result
16
+ reset_errors
19
17
  validate_pnote_document
20
- return @result
21
- end
22
-
23
- def has_error?
24
- return error_count > 0
25
- end
26
-
27
- def has_warning?
28
- return warning_count > 0
29
- end
30
-
31
- def error_count
32
- return @result[:errors].length
33
- end
34
-
35
- def warning_count
36
- return @result[:warnings].length
18
+ return @errors
37
19
  end
38
20
 
39
21
  private
40
22
 
41
- def reset_result
42
- @result = {
43
- errors: [],
44
- warnings: []
45
- }
46
- end
47
-
48
23
  def validate_pnote_document
24
+ practice_number = 1
25
+
49
26
  @pnote_document.chapters.each do |chapter|
50
27
  chapter.sub_chapters.each do |sub_chapter|
51
28
  chapter.practices.each do |practice|
52
- validation_result = validate_problem(practice)
53
- add_result(validation_result)
54
- end
55
-
56
- sub_chapter.exercises.each do |exercise|
57
- validation_result = validate_problem(exercise)
58
- add_result(validation_result)
29
+ validate_problem(practice, practice_number)
30
+ practice_number += 1
59
31
  end
60
32
 
61
33
  sub_chapter.practices.each do |practice|
62
- validation_result = validate_problem(practice)
63
- add_result(validation_result)
34
+ validate_problem(practice, practice_number)
35
+ practice_number += 1
64
36
  end
65
37
  end
66
38
  end
67
39
  end
68
40
 
69
- def validate_problem(problem)
41
+ def validate_problem(problem, practice_number)
70
42
  if problem.answer
71
- if problem.answer.length > 255
72
- return {
73
- valid: false,
74
- type: :error,
75
- message: "문제 정답의 길이가 255자보다 큽니다.",
76
- detail: "문제 질문: #{problem.question}\n문제 정답: #{problem.answer}"
77
- }
78
- end
79
-
80
43
  if problem.answer.length >= 15
81
- return {
82
- valid: false,
83
- type: :warning,
84
- message: "문제 정답의 길이가 15자 이상입니다.",
85
- detail: "문제 질문: #{problem.question}\n문제 정답: #{problem.answer}"
86
- }
44
+ add_error(
45
+ make_error(
46
+ title: "문제 정답의 길이가 15자 이상입니다.",
47
+ practice_number: practice_number,
48
+ type: "문제 정답",
49
+ detail: problem.answer
50
+ )
51
+ )
87
52
  end
88
53
  end
89
-
90
- return {
91
- valid: true,
92
- type: :success
93
- }
94
- end
95
-
96
- def add_result(validation_result)
97
- return if validation_result[:valid]
98
-
99
- if validation_result[:type] == :error
100
- @result[:errors] << {
101
- message: validation_result[:message],
102
- detail: validation_result[:detail]
103
- }
104
- elsif validation_result[:type] == :warning
105
- @result[:warnings] << {
106
- message: validation_result[:message],
107
- detail: validation_result[:detail]
108
- }
109
- end
110
54
  end
111
55
  end
112
56
  end
@@ -0,0 +1,39 @@
1
+ #
2
+ # Author: osh
3
+ # Created: 2019-05-27
4
+ # Last modified: 2019-05-27
5
+
6
+
7
+ module PnoteClient
8
+ module Validators
9
+ class Validator
10
+ def initialize
11
+ @errors = []
12
+ end
13
+
14
+ def has_error?
15
+ return error_count > 0
16
+ end
17
+
18
+ def error_count
19
+ return @errors.length
20
+ end
21
+
22
+ protected
23
+
24
+ def reset_errors
25
+ @errors = []
26
+ end
27
+
28
+ def add_error(error_msg)
29
+ @errors << error_msg
30
+ end
31
+
32
+ def make_error(title:, problem_number:, type:, detail: nil)
33
+ return "[에러 메시지] #{title}\n" +
34
+ "[에러 위치] 문제 #{problem_number}번, 유형: (#{type})\n" +
35
+ "[상세 내용]\n#{detail}"
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module PnoteClient
2
- VERSION = "2.5.0"
2
+ VERSION = "2.6.0"
3
3
  end
data/lib/pnote_client.rb CHANGED
@@ -1,4 +1,28 @@
1
1
  require "pnote_client/version"
2
2
 
3
3
  module PnoteClient
4
+ STYLES = {
5
+ chapter: "단원",
6
+ sub_chapter_title: "개념군",
7
+ concept_title: "개념",
8
+ concept_content: "개념 본문",
9
+ exercise_question: "예제 문제",
10
+ exercise_continuous_question: "예제(그림, 표, 박스, 글)",
11
+ exercise_answer: "예제 정답",
12
+ exercise_explaination: "예제 정답 해설",
13
+ practice_question: "문제",
14
+ practice_continuous_question: "문제(그림, 표, 박스, 글)",
15
+ practice_answer: "문제 정답",
16
+ practice_explaination: "문제 정답 해설",
17
+ practice_teacher_comment: [
18
+ "각주(선생님한테 과외받기)",
19
+ "코멘트1",
20
+ "코멘트2",
21
+ "코멘트3",
22
+ "코멘트4",
23
+ "코멘트5"
24
+ ],
25
+ choice: "보기",
26
+ tip_content: "꿀팁"
27
+ }
4
28
  end
data/pnote_client.gemspec CHANGED
@@ -31,5 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "rspec", "~> 3.0"
32
32
 
33
33
  spec.add_dependency "nokogiri"
34
- spec.add_dependency "hwp_script_to_latex", '~> 1.4.0'
34
+ spec.add_dependency "hwp_script_to_latex", '~> 1.6.0'
35
35
  end
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: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bluesh55
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-23 00:00:00.000000000 Z
11
+ date: 2019-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.4.0
75
+ version: 1.6.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.4.0
82
+ version: 1.6.0
83
83
  description:
84
84
  email:
85
85
  - bluesh55@naver.com
@@ -98,7 +98,6 @@ files:
98
98
  - Rakefile
99
99
  - bin/console
100
100
  - bin/setup
101
- - config.json
102
101
  - exe/pnote_clean
103
102
  - exe/pnote_to_json
104
103
  - lib/pnote_client.rb
@@ -128,6 +127,7 @@ files:
128
127
  - lib/pnote_client/utils/string_util.rb
129
128
  - lib/pnote_client/validators/hml_validator.rb
130
129
  - lib/pnote_client/validators/pnote_validator.rb
130
+ - lib/pnote_client/validators/validator.rb
131
131
  - lib/pnote_client/version.rb
132
132
  - pnote_client.gemspec
133
133
  homepage: https://github.com/PrivateCoach/pnote_client
data/config.json DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "hml_pnote_styles": {
3
- "chapter": "단원",
4
- "sub_chapter_title": "개념군",
5
- "concept_title": "개념",
6
- "concept_content": "개념 본문",
7
- "exercise_question": "예제 문제",
8
- "exercise_continuous_question": "예제(그림, 표, 박스, 글)",
9
- "exercise_answer": "예제 정답",
10
- "exercise_explaination": "예제 정답 해설",
11
- "practice_question": "문제",
12
- "practice_continuous_question": "문제(그림, 표, 박스, 글)",
13
- "practice_answer": "문제 정답",
14
- "practice_explaination": "문제 정답 해설",
15
- "practice_teacher_comment": [
16
- "각주(선생님한테 과외받기)",
17
- "코멘트1",
18
- "코멘트2",
19
- "코멘트3",
20
- "코멘트4",
21
- "코멘트5"
22
- ],
23
- "choice": "보기",
24
- "tip_content": "꿀팁"
25
- }
26
- }