Class: Hash::EmpConverter

Inherits:
Object
  • Object
show all
Extended by:
Empathy::EmpJson::Helpers::Primitives
Defined in:
lib/empathy/emp_json/helpers/hash.rb

Overview

Converts hash to emp_json

Constant Summary

Constants included from Empathy::EmpJson::Helpers::Primitives

Empathy::EmpJson::Helpers::Primitives::EMP_TYPE_BOOL, Empathy::EmpJson::Helpers::Primitives::EMP_TYPE_DATE, Empathy::EmpJson::Helpers::Primitives::EMP_TYPE_DATETIME, Empathy::EmpJson::Helpers::Primitives::EMP_TYPE_DOUBLE, Empathy::EmpJson::Helpers::Primitives::EMP_TYPE_GLOBAL_ID, Empathy::EmpJson::Helpers::Primitives::EMP_TYPE_INTEGER, Empathy::EmpJson::Helpers::Primitives::EMP_TYPE_LANGSTRING, Empathy::EmpJson::Helpers::Primitives::EMP_TYPE_LOCAL_ID, Empathy::EmpJson::Helpers::Primitives::EMP_TYPE_LONG, Empathy::EmpJson::Helpers::Primitives::EMP_TYPE_PRIMITIVE, Empathy::EmpJson::Helpers::Primitives::EMP_TYPE_STRING, Empathy::EmpJson::Helpers::Primitives::RDF_RDFS, Empathy::EmpJson::Helpers::Primitives::RDF_RDFV, Empathy::EmpJson::Helpers::Primitives::RDF_RDFV_LANGSTRING, Empathy::EmpJson::Helpers::Primitives::RDF_XSD, Empathy::EmpJson::Helpers::Primitives::RDF_XSD_BOOLEAN, Empathy::EmpJson::Helpers::Primitives::RDF_XSD_DATE, Empathy::EmpJson::Helpers::Primitives::RDF_XSD_DATETIME, Empathy::EmpJson::Helpers::Primitives::RDF_XSD_DECIMAL, Empathy::EmpJson::Helpers::Primitives::RDF_XSD_DOUBLE, Empathy::EmpJson::Helpers::Primitives::RDF_XSD_FLOAT, Empathy::EmpJson::Helpers::Primitives::RDF_XSD_INTEGER, Empathy::EmpJson::Helpers::Primitives::RDF_XSD_STRING, Empathy::EmpJson::Helpers::Primitives::RDF_XSD_TOKEN

Class Method Summary collapse

Methods included from Empathy::EmpJson::Helpers::Primitives

integer_to_value, node_to_local_id, object_to_value, primitive, primitive_to_value, rdf_literal_to_value, shorthand, throw_unknown_ruby_object, use_rdf_rb_for_primitive

Class Method Details

.convert(hash) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/empathy/emp_json/helpers/hash.rb', line 10

def convert(hash)
  hash.each_with_object({}) do |(key, value), slice|
    slice[key.to_s] = value.transform_keys(&:to_s).transform_values do |v|
      case v
      when Hash
        v
      when Array
        v.map(&method(:object_to_value))
      else
        object_to_value(v)
      end
    end
    slice[key.to_s]["_id"] = object_to_value(key)
    slice
  end
end