<commit_before>module TripIt
  class Base
    extend TripIt::ParamUtil

    def chkAndPopulate(iVar, objType, prop)
      return if prop.nil?
      if prop.is_a?(Array)
        prop.each do |value|
          iVar << objType.new(value)
        end
      else
        iVar << objType.new(prop)
      end
    end
    
    def chkObjAndPopulate(client, iVar, objType, prop)
      return if prop.nil?
      if prop.is_a?(Array)
        prop.each do |value|
          iVar << objType.new(client, value["id"], value)
        end
      else
        iVar << objType.new(client, prop["id"], prop)
      end
    end
    
    # Convert a TripIt DateTime Object to a Ruby DateTime Object
    def convertDT(tpitDT)
      return nil if tpitDT.nil?
      date = tpitDT["date"]
      time = tpitDT["time"]
      offset = tpitDT["utc_offset"]
      if time.nil?
        # Just return a date
        Date.parse(tpitDT["date"])
      else
        DateTime.parse(tpitDT["date"] + "T" + tpitDT["time"] + tpitDT["utc_offset"])
      end
    end

    # Convert object to (crude) XML for create (API does not seem to accept JSON)
    def to_xml<commit_msg>Handle TripIt just returning a Time<commit_after>module TripIt
  class Base
    extend TripIt::ParamUtil

    def chkAndPopulate(iVar, objType, prop)
      return if prop.nil?
      if prop.is_a?(Array)
        prop.each do |value|
          iVar << objType.new(value)
        end
      else
        iVar << objType.new(prop)
      end
    end
    
    def chkObjAndPopulate(client, iVar, objType, prop)
      return if prop.nil?
      if prop.is_a?(Array)
        prop.each do |value|
          iVar << objType.new(client, value["id"], value)
        end
      else
        iVar << objType.new(client, prop["id"], prop)
      end
    end
    
    # Convert a TripIt DateTime Object to a Ruby DateTime Object
    def convertDT(tpitDT)
      return nil if tpitDT.nil?
      date = tpitDT["date"]
      time = tpitDT["time"]
      offset = tpitDT["utc_offset"]
      if time.nil?
        # Just return a date
        Date.parse(tpitDT["date"])
      elsif date.nil?
        # Or just a time
        Time.parse(tpitDT["time"])
      else
        # Ideally both
        DateTime.parse(tpitDT["date"] + "T" + tpitDT["time"] + tpitDT["utc_offset"])
      end
    end

    # Convert object to (crude) XML for create (API does not seem to accept JSON)
    def to_xml
{'fraction_non_alphanumeric': 0.104227710339054, 'fraction_numerical': 0.0, 'mean_word_length': 2.06803594351733, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3905721', 'n_tokens_mistral': 789, 'n_tokens_neox': 778, 'n_words': 219}