Almirah 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,191 +0,0 @@
1
- require_relative "doc_items/doc_item"
2
- require_relative "doc_items/heading"
3
- require_relative "doc_items/paragraph"
4
- require_relative "doc_items/blockquote"
5
- require_relative "doc_items/controlled_paragraph"
6
- require_relative "doc_items/markdown_table"
7
- require_relative "doc_items/image"
8
- require_relative "doc_items/markdown_list"
9
-
10
- class Specification
11
-
12
- attr_accessor :path
13
- attr_accessor :docItems
14
- attr_accessor :title
15
- attr_accessor :key
16
- attr_accessor :up_link_key
17
- attr_accessor :dictionary
18
- attr_accessor :controlledParagraphs
19
- attr_accessor :tempMdTable
20
- attr_accessor :tempMdList
21
-
22
- def initialize(fele_path)
23
-
24
- @path = fele_path
25
- @title = ""
26
- @docItems = Array.new
27
- @controlledParagraphs = Array.new
28
- @dictionary = Hash.new
29
- @tempMdTable = nil
30
- @tempMdList = nil
31
-
32
- @key = File.basename(fele_path, File.extname(fele_path)).upcase
33
- @up_link_key = ""
34
-
35
- self.parse()
36
- end
37
-
38
- def parse()
39
-
40
- file = File.open( self.path )
41
- file_lines = file.readlines
42
- file.close
43
-
44
- file_lines.each do |s|
45
- if s.lstrip != ""
46
- if res = /^([#]{1,})\s(.*)/.match(s) # Heading
47
-
48
- if @tempMdTable
49
- self.docItems.append(@tempMdTable)
50
- @tempMdTable = nil
51
- end
52
- if @tempMdList
53
- self.docItems.append(@tempMdList)
54
- @tempMdList = nil
55
- end
56
-
57
- level = res[1].length
58
- value = res[2]
59
- item = Heading.new(value, level)
60
- self.docItems.append(item)
61
-
62
- if level == 1
63
- self.title = value
64
- end
65
-
66
- elsif res = /^\[(\S*)\]\s+(.*)/.match(s) # Controlled Paragraph
67
-
68
- if @tempMdTable
69
- self.docItems.append(@tempMdTable)
70
- @tempMdTable = nil
71
- end
72
- if @tempMdList
73
- self.docItems.append(@tempMdList)
74
- @tempMdList = nil
75
- end
76
-
77
- id = res[1]
78
- text = res[2]
79
-
80
- #check if it contains the uplink
81
- if tmp = /(.*)\s+>\[(\S*)\]$/.match(text)
82
-
83
- text = tmp[1]
84
- up_link = tmp[2]
85
-
86
- if tmp = /^([a-zA-Z]+)[-]\d+/.match(up_link)
87
- self.up_link_key = tmp[1]
88
- end
89
- end
90
-
91
- item = ControlledParagraph.new( text, id )
92
- item.up_link = up_link
93
-
94
- self.docItems.append(item)
95
- self.dictionary[ id.to_s ] = item #for fast search
96
- self.controlledParagraphs.append(item) #for fast search
97
-
98
- elsif res = /^[!]\[(.*)\]\((.*)\)/.match(s) # Image
99
-
100
- if @tempMdTable
101
- self.docItems.append(@tempMdTable)
102
- @tempMdTable = nil
103
- end
104
- if @tempMdList
105
- self.docItems.append(@tempMdList)
106
- @tempMdList = nil
107
- end
108
-
109
- img_text = res[1]
110
- img_path = res[2]
111
-
112
- item = Image.new( img_text, img_path )
113
-
114
- self.docItems.append(item)
115
-
116
- elsif res = /^(\*\s?)+(.*)/.match(s) #check if bullet list
117
-
118
- if @tempMdTable
119
- self.docItems.append(@tempMdTable)
120
- @tempMdTable = nil
121
- end
122
-
123
- row = res[2]
124
-
125
- if @tempMdList
126
- @tempMdList.addRow(row)
127
- else
128
- item = MarkdownList.new(row)
129
- @tempMdList = item
130
- end
131
-
132
- elsif s[0] == '|' #check if table
133
-
134
- if @tempMdList
135
- self.docItems.append(@tempMdList)
136
- @tempMdList = nil
137
- end
138
-
139
- if res = /^[|](-{3,})[|]/.match(s) #check if it is a separator first
140
-
141
- if @tempMdTable
142
- #separator is found after heading - just skip it
143
- else
144
- #separator out of table scope consider it just as a regular paragraph
145
- item = Paragraph.new(s)
146
- self.docItems.append(item)
147
- end
148
-
149
- elsif res = /^[|](.*[|])/.match(s) #check if it looks as a table
150
-
151
- row = res[1]
152
-
153
- if @tempMdTable
154
- @tempMdTable.addRow(row)
155
- else
156
- #start table from heading
157
- @tempMdTable = MarkdownTable.new(row)
158
- end
159
- end
160
-
161
- elsif res = /^[>](.*)/.match(s) #check if blockquote
162
-
163
- if @tempMdTable
164
- self.docItems.append(@tempMdTable)
165
- @tempMdTable = nil
166
- end
167
- if @tempMdList
168
- self.docItems.append(@tempMdList)
169
- @tempMdList = nil
170
- end
171
-
172
- item = Blockquote.new(res[1])
173
- self.docItems.append(item)
174
-
175
- else # Reqular Paragraph
176
- if @tempMdTable
177
- self.docItems.append(@tempMdTable)
178
- @tempMdTable = nil
179
- end
180
- if @tempMdList
181
- self.docItems.append(@tempMdList)
182
- @tempMdList = nil
183
- end
184
-
185
- item = Paragraph.new(s)
186
- self.docItems.append(item)
187
- end
188
- end
189
- end
190
- end
191
- end