languages/ruby/lib/oso/polar/host.rb
def to_polar(value) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
        value = case true # rubocop:disable Lint/LiteralAsCondition
                when value.instance_of?(TrueClass) || value.instance_of?(FalseClass)
                  { 'Boolean' => value }
                when value.instance_of?(Integer)
                  { 'Number' => { 'Integer' => value } }
                when value.instance_of?(Float)
                  if value == Float::INFINITY
                    value = 'Infinity'
                  elsif value == -Float::INFINITY
                    value = '-Infinity'
                  elsif value.nan?
                    value = 'NaN'
                  end
                  { 'Number' => { 'Float' => value } }
                when value.instance_of?(String)
                  { 'String' => value }
                when value.instance_of?(Array)
                  { 'List' => value.map { |el| to_polar(el) } }
                when value.instance_of?(Hash)
                  { 'Dictionary' => { 'fields' => value.transform_values { |v| to_polar(v) } } }
                when value.instance_of?(Predicate)
                  { 'Call' => { 'name' => value.name, 'args' => value.args.map { |el| to_polar(el) } } }
                when value.instance_of?(Variable)
                  # This is supported so that we can query for unbound variables
                  { 'Variable' => value }
                else
                  { 'ExternalInstance' => { 'instance_id' => cache_instance(value), 'repr' => value.to_s } }
                end
        { 'value' => value }
      end
# Turn a Ruby value into a Polar term that's ready to be sent across the
# FFI boundary.
#
# @param value [Object]
# @return [Hash<String, Object>]
Turn a Ruby value into a Polar term that's ready to be sent across the
FFI boundary.
Turn a Ruby value into a Polar term that ' s ready to be sent across the FFI boundary .
def to_polar(value) 
        value = case true 
                when value.instance_of?(TrueClass) || value.instance_of?(FalseClass)
                  { 'Boolean' => value }
                when value.instance_of?(Integer)
                  { 'Number' => { 'Integer' => value } }
                when value.instance_of?(Float)
                  if value == Float::INFINITY
                    value = 'Infinity'
                  elsif value == -Float::INFINITY
                    value = '-Infinity'
                  elsif value.nan?
                    value = 'NaN'
                  end
                  { 'Number' => { 'Float' => value } }
                when value.instance_of?(String)
                  { 'String' => value }
                when value.instance_of?(Array)
                  { 'List' => value.map { |el| to_polar(el) } }
                when value.instance_of?(Hash)
                  { 'Dictionary' => { 'fields' => value.transform_values { |v| to_polar(v) } } }
                when value.instance_of?(Predicate)
                  { 'Call' => { 'name' => value.name, 'args' => value.args.map { |el| to_polar(el) } } }
                when value.instance_of?(Variable)
                  { 'Variable' => value }
                else
                  { 'ExternalInstance' => { 'instance_id' => cache_instance(value), 'repr' => value.to_s } }
                end
        { 'value' => value }
      end
def to_polar ( value ) value = case true when value . instance_of? ( TrueClass ) || value . instance_of? ( FalseClass ) { 'Boolean' => value } when value . instance_of? ( Integer ) { 'Number' => { 'Integer' => value } } when value . instance_of? ( Float ) if value == Float :: INFINITY value = 'Infinity' elsif value == - Float :: INFINITY value = '-Infinity' elsif value . nan? value = 'NaN' end { 'Number' => { 'Float' => value } } when value . instance_of? ( String ) { 'String' => value } when value . instance_of? ( Array ) { 'List' => value . map { | el | to_polar ( el ) } } when value . instance_of? ( Hash ) { 'Dictionary' => { 'fields' => value . transform_values { | v | to_polar ( v ) } } } when value . instance_of? ( Predicate ) { 'Call' => { 'name' => value . name , 'args' => value . args . map { | el | to_polar ( el ) } } } when value . instance_of? ( Variable ) { 'Variable' => value } else { 'ExternalInstance' => { 'instance_id' => cache_instance ( value ) , 'repr' => value . to_s } } end { 'value' => value } end
Turn a Ruby value into a Polar term that's ready to be sent across the
FFI boundary.
Turn a Ruby value into a Polar term that ' s ready to be sent across the FFI boundary .
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity # rubocop:disable Lint/LiteralAsCondition # This is supported so that we can query for unbound variables
None
Hash<String, Object>
value
None