Class: Kvn::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/kvn/converter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Converter

Returns a new instance of Converter.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/kvn/converter.rb', line 7

def initialize(value)
  @value = begin
             (value || {}).to_h
           rescue
             {}
           end

  if invalid_values_present?
    message = "All values must be a supported type! #{Kvn::SUPPORTED_VALUE_TYPES.join ", "}"
    raise Kvn::UnsupportedHashError.new(message)
  end
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/kvn/converter.rb', line 5

def value
  @value
end

Instance Method Details

#convertObject



20
21
22
23
24
25
26
27
# File 'lib/kvn/converter.rb', line 20

def convert
  value.keys.sort.each_with_object([]) { |key, memo|
    v = value[key]
    v = "null" if v.nil?
    next if v.to_s.strip.empty?
    memo << "#{key}:#{v};"
  }.join(" ")
end