Class: XDG::Pair

Inherits:
Data
  • Object
show all
Defined in:
lib/xdg/pair.rb

Overview

A generic key-value pair (KVP).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key: nil, value: nil) ⇒ Pair

Returns a new instance of Pair.



6
7
8
# File 'lib/xdg/pair.rb', line 6

def initialize key: nil, value: nil
  super
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



5
6
7
# File 'lib/xdg/pair.rb', line 5

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



5
6
7
# File 'lib/xdg/pair.rb', line 5

def value
  @value
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


14
# File 'lib/xdg/pair.rb', line 14

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

#inspectObject



22
23
24
25
# File 'lib/xdg/pair.rb', line 22

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

#key?Boolean

Returns:

  • (Boolean)


10
# File 'lib/xdg/pair.rb', line 10

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

#to_envObject



16
# File 'lib/xdg/pair.rb', line 16

def to_env = {key => value}

#to_sObject Also known as: to_str



18
# File 'lib/xdg/pair.rb', line 18

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

#value?Boolean

Returns:

  • (Boolean)


12
# File 'lib/xdg/pair.rb', line 12

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