Class: Specification
- Inherits:
-
Object
- Object
- Specification
- Defined in:
- lib/almirah/specification.rb
Instance Attribute Summary collapse
-
#controlledParagraphs ⇒ Object
Returns the value of attribute controlledParagraphs.
-
#dictionary ⇒ Object
Returns the value of attribute dictionary.
-
#docItems ⇒ Object
Returns the value of attribute docItems.
-
#key ⇒ Object
Returns the value of attribute key.
-
#path ⇒ Object
Returns the value of attribute path.
-
#tempMdTable ⇒ Object
Returns the value of attribute tempMdTable.
-
#title ⇒ Object
Returns the value of attribute title.
-
#up_link_key ⇒ Object
Returns the value of attribute up_link_key.
Instance Method Summary collapse
-
#initialize(fele_path) ⇒ Specification
constructor
A new instance of Specification.
- #parse ⇒ Object
Constructor Details
#initialize(fele_path) ⇒ Specification
Returns a new instance of Specification.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/almirah/specification.rb', line 19 def initialize(fele_path) @path = fele_path @title = "" @docItems = Array.new @controlledParagraphs = Array.new @dictionary = Hash.new @tempMdTable = nil @key = File.basename(fele_path, File.extname(fele_path)).upcase @up_link_key = "" self.parse() end |
Instance Attribute Details
#controlledParagraphs ⇒ Object
Returns the value of attribute controlledParagraphs.
16 17 18 |
# File 'lib/almirah/specification.rb', line 16 def controlledParagraphs @controlledParagraphs end |
#dictionary ⇒ Object
Returns the value of attribute dictionary.
15 16 17 |
# File 'lib/almirah/specification.rb', line 15 def dictionary @dictionary end |
#docItems ⇒ Object
Returns the value of attribute docItems.
11 12 13 |
# File 'lib/almirah/specification.rb', line 11 def docItems @docItems end |
#key ⇒ Object
Returns the value of attribute key.
13 14 15 |
# File 'lib/almirah/specification.rb', line 13 def key @key end |
#path ⇒ Object
Returns the value of attribute path.
10 11 12 |
# File 'lib/almirah/specification.rb', line 10 def path @path end |
#tempMdTable ⇒ Object
Returns the value of attribute tempMdTable.
17 18 19 |
# File 'lib/almirah/specification.rb', line 17 def tempMdTable @tempMdTable end |
#title ⇒ Object
Returns the value of attribute title.
12 13 14 |
# File 'lib/almirah/specification.rb', line 12 def title @title end |
#up_link_key ⇒ Object
Returns the value of attribute up_link_key.
14 15 16 |
# File 'lib/almirah/specification.rb', line 14 def up_link_key @up_link_key end |
Instance Method Details
#parse ⇒ Object
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/almirah/specification.rb', line 34 def parse() file = File.open( self.path ) file_lines = file.readlines file.close file_lines.each do |s| if s.lstrip != "" if res = /^([#]{1,})\s(.*)/.match(s) # Heading if @tempMdTable self.docItems.append(@tempMdTable) @tempMdTable = nil end level = res[1].length value = res[2] item = Heading.new(value, level) self.docItems.append(item) if level == 1 self.title = value end elsif res = /^\[(\S*)\]\s+(.*)/.match(s) # Controlled Paragraph if @tempMdTable self.docItems.append(@tempMdTable) @tempMdTable = nil end id = res[1] text = res[2] item = ControlledParagraph.new( text, id ) #check if it contains the uplink if tmp = /(.*)\s+>\[(\S*)\]$/.match(text) text = tmp[1] up_link = tmp[2] item.up_link = up_link if tmp = /^([a-zA-Z]+)[-]\d+/.match(up_link) self.up_link_key = tmp[1] end end self.docItems.append(item) self.dictionary[ id.to_s ] = item #for fast search self.controlledParagraphs.append(item) #for fast search elsif s[0] == '|' #check if table if res = /^[|](-{3,})[|]/.match(s) #check if it is a separator first if @tempMdTable #separator is found after heading - just skip it else #separator out of table scope consider it just as a regular paragraph item = Paragraph.new(s) self.docItems.append(item) end elsif res = /^[|](.*[|])/.match(s) #check if it looks as a table row = res[1] if @tempMdTable @tempMdTable.addRow(row) else #start table from heading @tempMdTable = MarkdownTable.new(row) end end elsif res = /^[>](.*)/.match(s) #check if blockquote if @tempMdTable self.docItems.append(@tempMdTable) @tempMdTable = nil end item = Blockquote.new(res[1]) self.docItems.append(item) else # Reqular Paragraph if @tempMdTable self.docItems.append(@tempMdTable) @tempMdTable = nil end item = Paragraph.new(s) self.docItems.append(item) end end end end |