Class: Kali::KeyValuePair

Inherits:
Object
  • Object
show all
Extended by:
Utils::Named
Defined in:
lib/kali/key_value_pair.rb

Direct Known Subclasses

Parameter, Property

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Named

method_name

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

#valueObject

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

#nameObject

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

#separatorObject

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_icsObject

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_sObject

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