Class: EventDb::OutlineReader
- Inherits:
-
Object
- Object
- EventDb::OutlineReader
- Defined in:
- lib/eventdb/outline_reader.rb
Constant Summary collapse
- HEADING_RE =
/^(\#{1,}) ## leading #### ([^#]+?) ## text - note: use non-greedy e.g. +? \#* ## (optional) trailing ## $/x
- LISTITEM_RE =
/^ \s* -\s+ ## space required after dash (-) (.+) ## text $/x
Class Method Summary collapse
- .parse(txt) ⇒ Object
-
.read(path) ⇒ Object
use - rename to read_file or from_file etc.
Class Method Details
permalink .parse(txt) ⇒ Object
[View source]
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 |
# File 'lib/eventdb/outline_reader.rb', line 24 def self.parse( txt ) outline=[] ## outline structure # note: cut out; remove all html comments e.g. <!-- --> # supports multi-line comments too (e.g. uses /m - make dot match newlines) txt = txt.gsub( /<!-- .+? -->/xm, '' ) ## todo/fix: track/log cut out comments!!! txt.each_line do |line| line = line.strip ## todo/fix: keep leading and trailing spaces - why? why not? next if line.empty? ## todo/fix: keep blank line nodes e.g. just remove comments and process headings?! - why? why not? break if line == '__END__' pp line ## note: all optional trailing ### too if HEADING_RE.match( line ) heading_marker = $1 heading_level = $1.length ## count number of = for heading level heading = $2.strip puts "heading #{heading_level} >#{heading}<" outline << [:"h#{heading_level}", heading] elsif LISTITEM_RE.match( line ) item = $1.strip puts "list item >#{item}<" outline << [:li, item] else ## assume it's a (plain/regular) text line outline << [:l, line] end end outline end |
permalink .read(path) ⇒ Object
use - rename to read_file or from_file etc. - why? why not?
6 7 8 9 |
# File 'lib/eventdb/outline_reader.rb', line 6 def self.read( path ) ## use - rename to read_file or from_file etc. - why? why not? txt = File.open( path, 'r:utf-8' ).read parse( txt ) end |