Sha256: 4bf27674ca59f88d618bc8540e387f2ef8d4a342db96458bc41b9abd40e69ff4

Contents?: true

Size: 575 Bytes

Versions: 11

Compression:

Stored size: 575 Bytes

Contents

# frozen_string_literal: true

module XDG
  # A generic key-value pair (KVP).
  Pair = Data.define :key, :value do
    def initialize key: nil, value: nil
      super
    end

    def key? = key.to_s.size.positive?

    def value? = value.to_s.size.positive?

    def empty? = !(key? && value?)

    def to_env = {key => value}

    def to_s = key? || value? ? "#{key}#{DELIMITER}#{value}" : ""

    alias_method :to_str, :to_s

    def inspect
      type = self.class
      key? || value? ? "#<data #{type} #{key}#{DELIMITER}#{value}>" : "#<data #{type}>"
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
xdg-8.10.0 lib/xdg/pair.rb
xdg-8.9.0 lib/xdg/pair.rb
xdg-8.8.0 lib/xdg/pair.rb
xdg-8.7.0 lib/xdg/pair.rb
xdg-8.6.0 lib/xdg/pair.rb
xdg-8.5.0 lib/xdg/pair.rb
xdg-8.4.1 lib/xdg/pair.rb
xdg-8.3.0 lib/xdg/pair.rb
xdg-8.2.0 lib/xdg/pair.rb
xdg-8.1.0 lib/xdg/pair.rb
xdg-8.0.0 lib/xdg/pair.rb