Class: PolyrexHeadings

Inherits:
Object
  • Object
show all
Defined in:
lib/polyrex-headings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_s) ⇒ PolyrexHeadings

Returns a new instance of PolyrexHeadings.



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
# File 'lib/polyrex-headings.rb', line 11

def initialize(raw_s)

  summary, *s = raw_s.split(/(?=(?:#|[^\n]+\n-+))/,2)

  a = if raw_s =~ /----/ then       

    s.join.lines.chunk{|x| x != "\n" }.map do |record, x| 

      if record then

        head = x.shift
        x.shift
        [head] + x.map{|y| '  ' + y}
      end
    end

  else

    s.join.split(/^\n*#/)[1..-1].map do |x|  

      lines = x.lines

      raw_heading = lines.shift.rstrip
      raw_indent = raw_heading.slice!(/#*/)
      n, heading = raw_indent.length, raw_heading.lstrip

      ([indent(n) + heading] + lines.map{|x| indent(n+1) + x}).join
    end

  end
  summary.sub!(/^(<\?)(ph|polyrex-headings)/,'\1polyrex')
  @to_polyrex = Polyrex.new.parse(summary + a.join)
end

Instance Attribute Details

#to_polyrexObject (readonly)

Returns the value of attribute to_polyrex.



9
10
11
# File 'lib/polyrex-headings.rb', line 9

def to_polyrex
  @to_polyrex
end