9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/commenter/parser.rb', line 9
def parse(docx_path, options = {})
doc = Docx::Document.open(docx_path)
metadata = (doc)
= doc.tables.length > 1 ? doc.tables[1] : doc.tables.first
raise "No comments table found in document" unless
raise "Comments table appears to be empty" if .row_count < 2
= []
(0...row_count - 1).each do |i|
row = .rows[i]
cells = row.cells.map { |c| c.text.strip }
next if cells.all?(&:empty?)
id = cells[0] || ""
body = id.include?("-") ? id.split("-").first : id
= {
id: id,
body: body,
locality: {
line_number: cells[1] && cells[1].empty? ? nil : cells[1],
clause: cells[2] && cells[2].empty? ? nil : cells[2],
element: cells[3] && cells[3].empty? ? nil : cells[3]
},
type: cells[4] || "",
comments: cells[5] || "",
proposed_change: cells[6] || ""
}
unless options[:exclude_observations]
[:observations] = cells[7] && cells[7].empty? ? nil : cells[7]
end
<< Comment.new()
end
CommentSheet.new(
version: "2012-03",
date: metadata[:date],
document: metadata[:document],
project: metadata[:project],
comments:
)
end
|