Class: MindWordsPlus
- Inherits:
-
Object
- Object
- MindWordsPlus
- Defined in:
- lib/mindwords.rb
Instance Attribute Summary collapse
-
#to_px ⇒ Object
readonly
Returns the value of attribute to_px.
Instance Method Summary collapse
-
#initialize(s, fields: %w(title content),, debug: false) ⇒ MindWordsPlus
constructor
A new instance of MindWordsPlus.
- #to_ph ⇒ Object
- #to_tree ⇒ Object
Constructor Details
#initialize(s, fields: %w(title content),, debug: false) ⇒ MindWordsPlus
Returns a new instance of MindWordsPlus.
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 |
# File 'lib/mindwords.rb', line 632 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_px ⇒ Object (readonly)
Returns the value of attribute to_px.
630 631 632 |
# File 'lib/mindwords.rb', line 630 def to_px @to_px end |
Instance Method Details
#to_ph ⇒ Object
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 |
# File 'lib/mindwords.rb', line 674 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('<','<').gsub('>','>') line += "\n" + txt.gsub('<br/>',"\n- ") + "\n" end lines << line end lines.join.gsub(/\n\n\n/,"\n\n") end |
#to_tree ⇒ Object
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 |
# File 'lib/mindwords.rb', line 702 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('<','<').gsub('>','>') indent = ' ' * (level+1) + '* ' line += "\n" + indent + txt.gsub('<br/>',"\n" + indent) end lines << line end lines.join("\n") end |