languages/ruby/lib/oso/polar/host.rb
def to_ruby(data) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
        tag, value = data['value'].first
        case tag
        when 'String', 'Boolean'
          value
        when 'Number'
          num = value.values.first
          if value.key? 'Float'
            case num
            when 'Infinity'
              return Float::INFINITY
            when '-Infinity'
              return -Float::INFINITY
            when 'NaN'
              return Float::NAN
            else
              unless value['Float'].is_a? Float # rubocop:disable Metrics/BlockNesting
                raise PolarRuntimeError, "Expected a floating point number, got \"#{value['Float']}\""
              end
            end
          end
          num
        when 'List'
          value.map { |el| to_ruby(el) }
        when 'Dictionary'
          value['fields'].transform_values { |v| to_ruby(v) }
        when 'ExternalInstance'
          get_instance(value['instance_id'])
        when 'Call'
          Predicate.new(value['name'], args: value['args'].map { |a| to_ruby(a) })
        when 'Variable'
          Variable.new(value['name'])
        else
          raise UnexpectedPolarTypeError, tag
        end
      end
# Turn a Polar term passed across the FFI boundary into a Ruby value.
#
# @param data [Hash<String, Object>]
# @option data [Integer] :id
# @option data [Integer] :offset Character offset of the term in its source string.
# @option data [Hash<String, Object>] :value
# @return [Object]
# @raise [UnexpectedPolarTypeError] if type cannot be converted to Ruby.
Turn a Polar term passed across the FFI boundary into a Ruby value.
Turn a Polar term passed across the FFI boundary into a Ruby value .
def to_ruby(data) 
        tag, value = data['value'].first
        case tag
        when 'String', 'Boolean'
          value
        when 'Number'
          num = value.values.first
          if value.key? 'Float'
            case num
            when 'Infinity'
              return Float::INFINITY
            when '-Infinity'
              return -Float::INFINITY
            when 'NaN'
              return Float::NAN
            else
              unless value['Float'].is_a? Float 
                raise PolarRuntimeError, "Expected a floating point number, got \"#{value['Float']}\""
              end
            end
          end
          num
        when 'List'
          value.map { |el| to_ruby(el) }
        when 'Dictionary'
          value['fields'].transform_values { |v| to_ruby(v) }
        when 'ExternalInstance'
          get_instance(value['instance_id'])
        when 'Call'
          Predicate.new(value['name'], args: value['args'].map { |a| to_ruby(a) })
        when 'Variable'
          Variable.new(value['name'])
        else
          raise UnexpectedPolarTypeError, tag
        end
      end
def to_ruby ( data ) tag , value = data [ 'value' ] . first case tag when 'String' , 'Boolean' value when 'Number' num = value . values . first if value . key? 'Float' case num when 'Infinity' return Float :: INFINITY when '-Infinity' return - Float :: INFINITY when 'NaN' return Float :: NAN else unless value [ 'Float' ] . is_a? Float raise PolarRuntimeError , "Expected a floating point number, got \"#{value['Float']}\"" end end end num when 'List' value . map { | el | to_ruby ( el ) } when 'Dictionary' value [ 'fields' ] . transform_values { | v | to_ruby ( v ) } when 'ExternalInstance' get_instance ( value [ 'instance_id' ] ) when 'Call' Predicate . new ( value [ 'name' ] , args : value [ 'args' ] . map { | a | to_ruby ( a ) } ) when 'Variable' Variable . new ( value [ 'name' ] ) else raise UnexpectedPolarTypeError , tag end end
Turn a Polar term passed across the FFI boundary into a Ruby value.
Turn a Polar term passed across the FFI boundary into a Ruby value .
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity # rubocop:disable Metrics/BlockNesting
None
Object
[UnexpectedPolarTypeError] if type cannot be converted to Ruby.
[ UnexpectedPolarTypeError ] if type cannot be converted to Ruby .
data
None
None