Sha256: b87b796033f686be268f5c3004db4ece9bcdbba9ca26650d43e05cc8cfaf5773

Contents?: true

Size: 1001 Bytes

Versions: 35

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

35 entries across 35 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.151 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.150 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.149 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.148 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.147 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.146 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.145 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.144 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.143 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.142 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.141 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.140 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.139 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.138 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.137 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.136 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.135 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.134 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.133 lib/open_classes/string/heading_helper.rb
tbpgr_utils-0.0.132 lib/open_classes/string/heading_helper.rb