Sha256: ddcae7e8721ae9336748f58b85f89e3ac312ab312d3ef668fde4f5663b9ae73a

Contents?: true

Size: 962 Bytes

Versions: 15

Compression:

Stored size: 962 Bytes

Contents

# frozen_string_literal: true

require 'pp'

module Lino
  module Utilities
    def map_and_join(collection, &block)
      collection.map { |item| block.call(item) }.join(' ')
    end

    def join_with(global_separator)
      lambda do |item|
        item[:components].join(item[:separator] || global_separator)
      end
    end

    def quote_with(global_character)
      lambda do |item|
        item.merge(
          components: resolve_components(item, global_character)
        )
      end
    end

    def missing?(value)
      value.nil? || (value.respond_to?(:empty?) && value.empty?)
    end

    private

    def resolve_components(item, global_character)
      components = item[:components]
      switch = components[0]

      if components.count > 1
        character = item[:quoting] || global_character
        value = components[1]

        [switch, "#{character}#{value}#{character}"]
      else
        components
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
lino-2.6.0.pre.1 lib/lino/utilities.rb
lino-2.5.0 lib/lino/utilities.rb
lino-2.4.0.pre.2 lib/lino/utilities.rb
lino-2.4.0.pre.1 lib/lino/utilities.rb
lino-2.3.0 lib/lino/utilities.rb
lino-2.2.0.pre.6 lib/lino/utilities.rb
lino-2.2.0.pre.5 lib/lino/utilities.rb
lino-2.2.0.pre.4 lib/lino/utilities.rb
lino-2.2.0.pre.3 lib/lino/utilities.rb
lino-2.2.0.pre.2 lib/lino/utilities.rb
lino-2.2.0.pre.1 lib/lino/utilities.rb
lino-2.1.0 lib/lino/utilities.rb
lino-2.0.0.pre.1 lib/lino/utilities.rb
lino-1.10.0.pre.2 lib/lino/utilities.rb
lino-1.10.0.pre.1 lib/lino/utilities.rb