<commit_before>module NetSuiteRails
  module Transformations
    class << self

      def transform(type, value, direction)
        self.send(type, value, direction)
      end

      # NS limits firstname fields to 33 characters
      def firstname(firstname, direction = :push)
        if direction == :push
          firstname[0..33]
        else
          firstname
        end
      end

      def phone(phone, direction = :push)
        if direction == :push
          formatted_phone = phone.
            strip.
            gsub(/ext(ension)?/, 'x').
            # remove anything that isn't a extension indicator or a number
            gsub(/[^0-9x]/, '').
            # if the first part of the phone # is 10 characters long and starts with a 1 the 22 char error is thrown
            gsub(/^1([0-9]{10})/, '\1')

          # eliminate the extension if the number is still too long
          formatted_phone.gsub!(/x.*$/, '') if formatted_phone.size > 22

          formatted_phone
        else
          phone
        end
      end

      # NS will throw an error if whitespace bumpers the email string
      def email(email, direction = :push)
        if direction == :push
          email.strip
        else
          email
        end
      end

      # https://www.reinteractive.net/posts/168-dealing-with-timezones-effectively-in-rails
      # http://stackoverflow.com/questions/16818180/ruby-rails-how-do-i-change-the-timezone-of-a-time-without-changing-the-time
      # http://alwayscoding.ca/momentos/2013/08/22/handling-dates-and-timezones-in-ruby-and-rails/

      def date(date, direction = :push)
        if direction == :push
          date.change(offset: "-07:00", hour: 24 - (8 + NetSuiteRails::Configuration.netsuite_instance_time_zone_offset))
        else
          date.change(offset: Time.zone.formatted_offset) + (8 + NetSuiteRails::Configuration.netsuite_instance_time_zone_offset).hours
        end
      end

      def datetime(datetime, direction = :push)
        if direction == :push
          datetime.change(offset: "-08:00", year: 1970, day: 01, month: 01) - (8 + NetSuiteRails::Configuration.netsuite_instance_time_zone_offset).hours<commit_msg>experimenting with a simplified method for date handlign<commit_after>module NetSuiteRails
  module Transformations
    class << self

      def transform(type, value, direction)
        self.send(type, value, direction)
      end

      # NS limits firstname fields to 33 characters
      def firstname(firstname, direction = :push)
        if direction == :push
          firstname[0..33]
        else
          firstname
        end
      end

      def phone(phone, direction = :push)
        if direction == :push
          formatted_phone = phone.
            strip.
            gsub(/ext(ension)?/, 'x').
            # remove anything that isn't a extension indicator or a number
            gsub(/[^0-9x]/, '').
            # if the first part of the phone # is 10 characters long and starts with a 1 the 22 char error is thrown
            gsub(/^1([0-9]{10})/, '\1')

          # eliminate the extension if the number is still too long
          formatted_phone.gsub!(/x.*$/, '') if formatted_phone.size > 22

          formatted_phone
        else
          phone
        end
      end

      # NS will throw an error if whitespace bumpers the email string
      def email(email, direction = :push)
        if direction == :push
          email.strip
        else
          email
        end
      end

      # https://www.reinteractive.net/posts/168-dealing-with-timezones-effectively-in-rails
      # http://stackoverflow.com/questions/16818180/ruby-rails-how-do-i-change-the-timezone-of-a-time-without-changing-the-time
      # http://alwayscoding.ca/momentos/2013/08/22/handling-dates-and-timezones-in-ruby-and-rails/

      def date(date, direction = :push)
        if direction == :push
          # setting the hour to noon eliminates the chance that some strange timezone offset
          # shifting would cause the date to drift into the next or previous day
          date.to_datetime.change(offset: "-07:00", hour: 12)
        else
          date.change(offset: Time.zone.formatted_offset)
        end
      end

      def datetime(datetime, direction = :push)
        if direction == :push
          datetime.change(offset: "-08:00", year: 1970, day: 01, month: 01) - (8 + NetSuiteRails::Configuration.netsuite_instance_time_zone_offset).hours
{'fraction_non_alphanumeric': 0.10020220175241519, 'fraction_numerical': 0.02651089642776904, 'mean_word_length': 2.1242105263157893, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '1065986', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1240, 'n_words': 352}