Sha256: b33de4ef9f83af5e4f95bc0e6c737922a77e947b28972eae5d7295012c07302a

Contents?: true

Size: 984 Bytes

Versions: 2

Compression:

Stored size: 984 Bytes

Contents

module Tabulo

  # @!visibility private
  module Util

    # @!visibility private
    def self.condense_lines(lines)
      join_lines(lines.reject(&:empty?))
    end

    # @!visibility private
    def self.divides?(smaller, larger)
      larger % smaller == 0
    end

    # @!visibility private
    def self.join_lines(lines)
      lines.join($/)
    end

    # @!visibility private
    def self.max(x, y)
      x > y ? x : y
    end

    # @!visibility private
    def self.slice_hash(hash, *keys)
      new_hash = {}
      keys.each { |k| new_hash[k] = hash[k] if hash.include?(k) }
      new_hash
    end

    # @!visibility private
    # @return [Integer] the length of the longest segment of str when split by newlines
    def self.wrapped_width(str)
      return 0 if str.empty?
      segments = str.split($/)
      segments.inject(1) do |longest_length_so_far, segment|
        Util.max(longest_length_so_far, Unicode::DisplayWidth.of(segment))
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tabulo-2.6.1 lib/tabulo/util.rb
tabulo-2.6.0 lib/tabulo/util.rb