class MyOutline::Outline

Attributes

ftx[R]
pxi[R]

Public Class Methods

new(source, debug: false, allsorted: true, autoupdate: true) click to toggle source
# File lib/myoutline.rb, line 22
def initialize(source, debug: false, allsorted: true, autoupdate: true)
  
  @debug, @source = debug, source
  @allsorted, @autoupdate = allsorted, autoupdate
  
  build_index(source)

end

Public Instance Methods

autosave(s=nil) click to toggle source
# File lib/myoutline.rb, line 31
def autosave(s=nil)
  
  puts ('inside autosave ; @autoupdate: ' + @autoupdate.inspect).debug if @debug
  
  if @autoupdate then
    puts 'before save'.info if @debug
    save() if s.nil? or self.to_s != s      
  end
  
end
build_html(&blk) click to toggle source
# File lib/myoutline.rb, line 42
def build_html(&blk)
  @pxi.build_html(&blk)
end
locate(s) click to toggle source
# File lib/myoutline.rb, line 46
def locate(s)
  @links.locate s
end
ls(path='.') click to toggle source
# File lib/myoutline.rb, line 50
def ls(path='.')
  @ftx.ls(path).map(&:to_s)
end
save(filename=nil) click to toggle source
# File lib/myoutline.rb, line 54
def save(filename=nil)
  
  if filename.nil? then
    filename = RXFHelper.writeable?(@source) ? @source : 'myoutline.txt'
  end

  RXFHelper.write filename, self.to_s(declaration: true)
  
end
to_px() click to toggle source
# File lib/myoutline.rb, line 64
def to_px()
  @pxi.to_px
end
to_s(declaration: false) click to toggle source
# File lib/myoutline.rb, line 68
def to_s(declaration: false)
  
  if declaration == true then
    @pxi.to_s.sub(/(?<=^\<\?)([^\?]+)/,'myoutline')
  else
    @pxi.to_s.lines[1..-1].join.lstrip
  end
  
end
to_tree() click to toggle source
# File lib/myoutline.rb, line 78
def to_tree
  format_tree(alphabet: true, nourl: true)
end

Private Instance Methods

build_index(s) click to toggle source
# File lib/myoutline.rb, line 88
def build_index(s)
  
  @pxi = PxIndex.new(debug: @debug, indexsorted: @indexsorted, 
                     allsorted: @allsorted)
  @pxi.import s
  autosave(s)
  read(self.to_treelinks)
  
end
format_tree(alphabet: false, nourl: false) click to toggle source
# File lib/myoutline.rb, line 98
def format_tree(alphabet: false, nourl: false)
  
  a  = @pxi.to_s.lines
  a.shift # remove the ph declaration
  a.reject! {|x| x =~ /^(?:#[^\n]+|\n+)$/} unless alphabet
  
  if nourl then
    # strip out the URLS?
    a.map! {|x| r = x[/^.*(?= # )/]; r ? r + "\n" : x }
  end
  
  a.join
  
end
read(s) click to toggle source
# File lib/myoutline.rb, line 113
def read(s)
  
  @links = PolyrexLinks.new.import(s, debug: @debug)
  
  s3 = s.lines.map {|x| x.split(/  | # /,2)[0]}.join("\n")
  @ftx = FileTreeXML.new(s3, debug: @debug)    
  
end