Class: MindWordsPlus

Inherits:
Object
  • Object
show all
Defined in:
lib/mindwords.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s, fields: %w(title content),, debug: false) ⇒ MindWordsPlus

Returns a new instance of MindWordsPlus.



588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
# File 'lib/mindwords.rb', line 588

def initialize(s, fields: %w(title content), debug: false)

  lt = LineTree.new(s)
  h = lt.to_h

  mw = MindWords.new(h.keys.join("\n"))
  outline = mw.to_outline

  out = outline.lines.map do |line|

    word = line[/\w[^$]+/]

    found = h.keys.find do |key, value|

      if debug then
        puts 'key2: ' + key[/^[^#]+(?= #)/].inspect
        puts 'word: ' + word.chomp.inspect
      end

      word.chomp == key[/^[^#]+(?= #)/]
    end

    puts 'found: ' + found.inspect if debug

    if found and h[found][:body] then
      puts '***' + h[found][:body].keys.inspect  if debug
      line.chomp + ' # ' + h[found][:body].keys.join('<br/>') + "\n"
    else
      line
    end

  end

  puts out.join if debug

  px = Polyrex.new(schema: "entries[title]/entry[#{fields.join(', ')}]",
                   delimiter: ' # ')
  px.import out.join
  @px = px

end

Instance Attribute Details

#to_pxObject (readonly)

Returns the value of attribute to_px.



586
587
588
# File 'lib/mindwords.rb', line 586

def to_px
  @to_px
end

Instance Method Details

#to_phObject



630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
# File 'lib/mindwords.rb', line 630

def to_ph()

  lines = []

  @px.each_recursive do |x, parent, level|

    if level.to_i < 3 then
      line = ("\n" + '#' * (level.to_i + 1)) + ' ' + x.title + "\n\n"
    else
      line = '*' + ' ' + x.title + "\n"
    end

    if x.content.length >= 1 then
      txt = '- ' + x.content.gsub('&lt;','<').gsub('&gt;','>')
      line += "\n" + txt.gsub('<br/>',"\n- ") + "\n"
    end

    lines << line

  end

  lines.join.gsub(/\n\n\n/,"\n\n")
end

#to_treeObject



658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
# File 'lib/mindwords.rb', line 658

def to_tree()

  lines = []
  @px.each_recursive do |x, parent, level|

    line = ('  ' * level) + x.title

    if x.content.length >= 1 then
      txt = x.content.gsub('&lt;','<').gsub('&gt;','>')
      indent = '  ' * (level+1) + '* '
      line += "\n" + indent +  txt.gsub('<br/>',"\n" + indent)
    end

    lines << line
  end

  lines.join("\n")

end