Sha256: a54d80a4c01f783a38153bd642ac5e5c3037fc098c602507cf4882b4e5273b78

Contents?: true

Size: 969 Bytes

Versions: 4

Compression:

Stored size: 969 Bytes

Contents

module Tabulo

  # @!visibility private
  module Util

    NEWLINE = /\r\n|\n|\r/

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

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

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

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

    # @!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(NEWLINE)
      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

4 entries across 4 versions & 1 rubygems

Version Path
tabulo-3.0.3 lib/tabulo/util.rb
tabulo-3.0.2 lib/tabulo/util.rb
tabulo-3.0.1 lib/tabulo/util.rb
tabulo-3.0.0 lib/tabulo/util.rb