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
44
45
46
47
48
49
50
# File 'lib/polyrex-headings.rb', line 11

def initialize(raw_s)

  # add an empty space to the blank line where there is no 
  # raw record between headings
  
  raw_s.gsub!(/(#+[^\n]+\n+)(?=\n#)/m,'\1 ')

  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_s = string = summary + a.join

  @to_polyrex = Polyrex.new.parse(string)
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

#to_sObject (readonly)

Returns the value of attribute to_s.



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

def to_s
  @to_s
end