Class: XDG::Pair
- Inherits:
-
Data
- Object
- Data
- XDG::Pair
- Defined in:
- lib/xdg/pair.rb
Overview
A generic key-value pair (KVP).
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(key: nil, value: nil) ⇒ Pair
constructor
A new instance of Pair.
- #inspect ⇒ Object
- #key? ⇒ Boolean
- #to_env ⇒ Object
- #to_s ⇒ Object (also: #to_str)
- #value? ⇒ Boolean
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
#key ⇒ Object (readonly)
Returns the value of attribute key
5 6 7 |
# File 'lib/xdg/pair.rb', line 5 def key @key end |
#value ⇒ Object (readonly)
Returns the value of attribute value
5 6 7 |
# File 'lib/xdg/pair.rb', line 5 def value @value end |
Instance Method Details
#empty? ⇒ Boolean
14 |
# File 'lib/xdg/pair.rb', line 14 def empty? = !(key? && value?) |
#inspect ⇒ Object
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
10 |
# File 'lib/xdg/pair.rb', line 10 def key? = key.to_s.size.positive? |
#to_env ⇒ Object
16 |
# File 'lib/xdg/pair.rb', line 16 def to_env = {key => value} |
#to_s ⇒ Object Also known as: to_str
18 |
# File 'lib/xdg/pair.rb', line 18 def to_s = key? || value? ? "#{key}#{DELIMITER}#{value}" : "" |
#value? ⇒ Boolean
12 |
# File 'lib/xdg/pair.rb', line 12 def value? = value.to_s.size.positive? |