Sha256: 3b9a509059a206fcdb243d72c162ec7dbe21c1a3923320f6a0d9e587eba47608

Contents?: true

Size: 1.01 KB

Versions: 23

Compression:

Stored size: 1.01 KB

Contents

module Gem
  module Release
    module Helper
      class Wrapper < Struct.new(:str, :width)
        MARKDOWN = /^(```|\*|-)/

        def apply
          paras = str.split("\n\n")
          paras.map { |para| wrap_paragraph(para) }.join("\n\n")
        end

        private

          def wrap_paragraph(str)
            return str if str =~ MARKDOWN
            wrap_lines(str.split("\n", width).join(' '))
          end

          def wrap_lines(str)
            str.split("\n\n").map do |str|
              str.size > width ? str.gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n").strip : str
            end.join("\n")
          end
      end

      module String
        def camelize(str)
          str.to_s.split(/[^a-z0-9]/i).map { |str| str.capitalize }.join
        end

        def underscore(str)
          str.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
            gsub(/([a-z\d])([A-Z])/,'\1_\2').
            downcase
        end

        def wrap(str, width)
          Wrapper.new(str, width).apply
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
gem-release-2.2.4 lib/gem/release/helper/string.rb
gem-release-2.2.3 lib/gem/release/helper/string.rb
gem-release-2.2.3.alpha4 lib/gem/release/helper/string.rb
gem-release-2.2.3.alpha3 lib/gem/release/helper/string.rb
gem-release-2.2.3.alpha2 lib/gem/release/helper/string.rb
gem-release-2.2.3.alpha1 lib/gem/release/helper/string.rb
gem-release-2.2.2 lib/gem/release/helper/string.rb
gem-release-2.2.1 lib/gem/release/helper/string.rb
gem-release-2.2.0 lib/gem/release/helper/string.rb
gem-release-2.1.1 lib/gem/release/helper/string.rb
gem-release-2.1.0 lib/gem/release/helper/string.rb
gem-release-2.0.4 lib/gem/release/helper/string.rb
gem-release-2.0.3 lib/gem/release/helper/string.rb
gem-release-2.0.2 lib/gem/release/helper/string.rb
gem-release-2.0.1 lib/gem/release/helper/string.rb
gem-release-2.0.0.rc.3 lib/gem/release/helper/string.rb
gem-release-2.0.0.rc.2 lib/gem/release/helper/string.rb
gem-release-2.0.0.rc.1 lib/gem/release/helper/string.rb
gem-release-2.0.0.dev.5 lib/gem/release/helper/string.rb
gem-release-2.0.0.dev.4 lib/gem/release/helper/string.rb