Sha256: 8068be8bcd3c156d37822d88569d8a89620b238b3b6c7af99dfb6425b828ceda

Contents?: true

Size: 1001 Bytes

Versions: 67

Compression:

Stored size: 1001 Bytes

Contents

# encoding: utf-8
require 'active_support/core_ext/object/inclusion'

# HeadingHelper
module HeadingHelper
  private
    def to_heading
      self_chars = chars
      level, index, word_ret, ret = 0, 0, [], []
      self_chars.each_with_index do |v, index|
        key_word = v.in? %w{> + ^}

        if key_word
          ret << leveled_word(level, word_ret)
          level += v == '+' ? 0 : v == '>' ? 1 : -1
          word_ret = []
        else
          word_ret << v
        end
      end
      ret << leveled_word(level, word_ret)
    end

    def leveled_word(level, words)
      word = {}
      word[:level] = level
      word[:word] = words.join
      word
    end

    def to_head(heading, head_char, options = { separator: '', start_level: 0 })
      heading.reduce([]) do |ret, value|
        repeat = (value[:level] + options[:start_level])
        ret << "#{head_char * repeat}#{options[:separator]}#{value[:word]}"
      end.join("\n")
    end
end

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.116 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.115 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.114 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.113 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.112 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.111 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.110 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.109 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.108 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.107 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.106 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.105 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.104 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.103 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.102 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.101 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.100 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.99 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.98 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.97 lib/open_classes/string/heading_helper.rb