Class: Kali::KeyValuePair
- Inherits:
-
Object
- Object
- Kali::KeyValuePair
- Extended by:
- Utils::Named
- Defined in:
- lib/kali/key_value_pair.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
Public: Get/Set the value of this specific instance of the KV-pair.
Class Method Summary collapse
-
.default(default = nil) ⇒ Object
Public: Get/Set a default value for this KV-pair.
-
.type(type = nil) ⇒ Object
Public: Get/Set the Type of the KV-pair implemented by this class.
-
.wrap(value) ⇒ Object
Internal: Given a value for this KV-pair, if it’s already of the pair’s type, return it as is, or otherwise instantiate a new pair with this as a value.
Instance Method Summary collapse
-
#initialize(value = self.class.default) ⇒ KeyValuePair
constructor
Internal: Initialize the KV-pair.
-
#name ⇒ Object
Internal: Get the name of the KV-pair.
-
#separator ⇒ Object
Internal: Separator of the key and value in iCalendar representations of this KV-pair.
-
#to_ics ⇒ Object
Public: Generate an iCalendar representation of this KV-pair.
-
#to_s ⇒ Object
Public: Get the String representation of this KV-pair.
Methods included from Utils::Named
Constructor Details
#initialize(value = self.class.default) ⇒ KeyValuePair
Internal: Initialize the KV-pair.
value - Any value that can be set for this KV-pair.
32 33 34 |
# File 'lib/kali/key_value_pair.rb', line 32 def initialize(value = self.class.default) @value = value end |
Instance Attribute Details
#value ⇒ Object
Public: Get/Set the value of this specific instance of the KV-pair.
27 28 29 |
# File 'lib/kali/key_value_pair.rb', line 27 def value @value end |
Class Method Details
.default(default = nil) ⇒ Object
Public: Get/Set a default value for this KV-pair.
21 22 23 24 |
# File 'lib/kali/key_value_pair.rb', line 21 def self.default(default = nil) @default = default if default @default end |
.type(type = nil) ⇒ Object
Public: Get/Set the Type of the KV-pair implemented by this class.
15 16 17 18 |
# File 'lib/kali/key_value_pair.rb', line 15 def self.type(type = nil) @type = type if type @type end |
.wrap(value) ⇒ Object
Internal: Given a value for this KV-pair, if it’s already of the pair’s type, return it as is, or otherwise instantiate a new pair with this as a value.
Returns an instance of this KV-pair’s type.
10 11 12 |
# File 'lib/kali/key_value_pair.rb', line 10 def self.wrap(value) self === value ? value : new(value) end |
Instance Method Details
#name ⇒ Object
Internal: Get the name of the KV-pair.
50 51 52 |
# File 'lib/kali/key_value_pair.rb', line 50 def name @name ||= self.class.name end |
#separator ⇒ Object
Internal: Separator of the key and value in iCalendar representations of this KV-pair.
Returns a String.
58 59 60 |
# File 'lib/kali/key_value_pair.rb', line 58 def separator ":" end |
#to_ics ⇒ Object
Public: Generate an iCalendar representation of this KV-pair.
Returns a String.
39 40 41 42 |
# File 'lib/kali/key_value_pair.rb', line 39 def to_ics encoded_value = self.class.type.encode(value) "#{name}#{separator}#{encoded_value}" end |
#to_s ⇒ Object
Public: Get the String representation of this KV-pair.
45 46 47 |
# File 'lib/kali/key_value_pair.rb', line 45 def to_s value.to_s end |