<commit_before># Copyright (c) 2011 VMware, Inc.  All Rights Reserved.
require 'time'

module RbVmomi

class NewDeserializer
  NS_XSI = 'http://www.w3.org/2001/XMLSchema-instance'

  DEMANGLED_ARRAY_TYPES = {
    'AnyType' => 'xsd:anyType',
    'DateTime' => 'xsd:dateTime',
  }
  %w(Boolean String Byte Short Int Long Float Double).each do |x|
    DEMANGLED_ARRAY_TYPES[x] = "xsd:#{x.downcase}"
  end

  BUILTIN_TYPE_ACTIONS = {
    'xsd:string' => :string,
    'xsd:boolean' => :boolean,
    'xsd:byte' => :int,
    'xsd:short' => :int,
    'xsd:int' => :int,
    'xsd:long' => :int,
    'xsd:float' => :float,
    'xsd:dateTime' => :date,
    'PropertyPath' => :string,
    'MethodName' => :string,
    'TypeName' => :string,
    'xsd:base64Binary' => :binary,
    'KeyValue' => :keyvalue,
  }

  BUILTIN_TYPE_ACTIONS.dup.each do |k,v|
    if k =~ /^xsd:/
      BUILTIN_TYPE_ACTIONS[$'] = v
    end
  end

  def initialize conn
    @conn = conn
    @loader = conn.class.loader
  end

  def deserialize node, type=nil
    if type_attr = node['type']
    elsif node.attributes['type']
      # Work around for 1.5.x which doesn't populate node['type']
      # XXX what changed
      type_attr = node.attributes['type'].value
    end

    type = type_attr if type_attr

    if action = BUILTIN_TYPE_ACTIONS[type]
      case action
      when :string
        node.content
      when :boolean
        node.content == '1' || node.content == 'true'<commit_msg>Rework awkward if statement<commit_after># Copyright (c) 2011 VMware, Inc.  All Rights Reserved.
require 'time'

module RbVmomi

class NewDeserializer
  NS_XSI = 'http://www.w3.org/2001/XMLSchema-instance'

  DEMANGLED_ARRAY_TYPES = {
    'AnyType' => 'xsd:anyType',
    'DateTime' => 'xsd:dateTime',
  }
  %w(Boolean String Byte Short Int Long Float Double).each do |x|
    DEMANGLED_ARRAY_TYPES[x] = "xsd:#{x.downcase}"
  end

  BUILTIN_TYPE_ACTIONS = {
    'xsd:string' => :string,
    'xsd:boolean' => :boolean,
    'xsd:byte' => :int,
    'xsd:short' => :int,
    'xsd:int' => :int,
    'xsd:long' => :int,
    'xsd:float' => :float,
    'xsd:dateTime' => :date,
    'PropertyPath' => :string,
    'MethodName' => :string,
    'TypeName' => :string,
    'xsd:base64Binary' => :binary,
    'KeyValue' => :keyvalue,
  }

  BUILTIN_TYPE_ACTIONS.dup.each do |k,v|
    if k =~ /^xsd:/
      BUILTIN_TYPE_ACTIONS[$'] = v
    end
  end

  def initialize conn
    @conn = conn
    @loader = conn.class.loader
  end

  def deserialize node, type=nil
    type_attr = node['type']

    # Work around for 1.5.x which doesn't populate node['type']
    # XXX what changed
    if node.attributes['type'] and not type_attr
      type_attr = node.attributes['type'].value
    end

    type = type_attr if type_attr

    if action = BUILTIN_TYPE_ACTIONS[type]
      case action
      when :string
        node.content
      when :boolean
        node.content == '1' || node.content == 'true'
{'fraction_non_alphanumeric': 0.14728946471189908, 'fraction_numerical': 0.00954653937947494, 'mean_word_length': 2.917222963951936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7196204', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1063, 'n_words': 246}