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.



5
6
7
8
9
10
11
12
# File 'lib/kvn/converter.rb', line 5

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

  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.



3
4
5
# File 'lib/kvn/converter.rb', line 3

def value
  @value
end

Instance Method Details

#convertObject



14
15
16
17
18
19
20
21
# File 'lib/kvn/converter.rb', line 14

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