Class: LineTree

Inherits:
Object
  • Object
show all
Defined in:
lib/line-tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_s, level: nil, ignore_non_element: true, ignore_blank_lines: true, ignore_label: false, ignore_newline: true, root: nil, debug: false) ⇒ LineTree

Returns a new instance of LineTree.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/line-tree.rb', line 13

def initialize(raw_s, level: nil, ignore_non_element: true, 
               ignore_blank_lines: true, ignore_label: false, 
               ignore_newline: true, root: nil, debug: false)
  
  puts 'inside linetree'.info if @debug
  s = root ? root + "\n" + raw_s.lines.map {|x| '  ' + x}.join : raw_s
  
  @ignore_non_element = ignore_non_element
  @ignore_label = ignore_label
  @ignore_blank_lines = ignore_blank_lines
  @ignore_newline = ignore_newline
  @debug = debug
  
  lines = ignore_blank_lines ? s.gsub(/^ *$\n/,'') : s
  puts ('lines : ' + lines.inspect).debug if @debug
  @to_a = scan_shift(lines.strip, level)
  
end

Instance Attribute Details

#to_aObject (readonly)

Returns the value of attribute to_a.



11
12
13
# File 'lib/line-tree.rb', line 11

def to_a
  @to_a
end

Instance Method Details

#to_doc(encapsulate: false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/line-tree.rb', line 32

def to_doc(encapsulate: false)    
  
  a = @to_a
  
  a2 = if a[0].is_a? Array then      
    encapsulate ? encap(a) : scan_a(a)
  else
    puts 'before scan_a' if @debug
    scan_a(*a)
  end
  
  a2.unshift('root', {})
  puts 'a2: ' + a2.inspect if @debug
  
  Rexle.new(a2)
  
end

#to_html(numbered: false) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/line-tree.rb', line 50

def to_html(numbered: false)
  
  @numbered = numbered
  s = "<ul>%s</ul>" % make_html_list(@to_a)
  puts ('s: ' + s.inspect).debug if @debug
  puts s if @debug
  Rexle.new(s).xml declaration: false
  
end

#to_xml(options = {}) ⇒ Object



60
61
62
# File 'lib/line-tree.rb', line 60

def to_xml(options={})
  to_doc.xml(options)
end