<commit_before>module RailsAdminSettings
  module Processing
    def text_type?
      ['string', 'html', 'sanitized', 'email', 'address'].include? type
    end

    def html_type?
      ['html', 'sanitized'].include? type
    end

    def integer_type?
      'integer' == type
    end

    def yaml_type?
      'yaml' == type
    end

    def email_type?
      'email' == type
    end

    def phone_type?
      'phone' == type
    end

    def address_type?
      'address' == type
    end

    def sanitized_type?
      'sanitized' == type
    end

    def file_type?
      'file' == type
    end

    def value
      if file_type?
        file.url
      elsif raw.blank? || disabled?
        default_value
      else
        processed_value
      end
    end

    def to_s
      if yaml_type? || phone_type? || integer_type?
        raw
      else
        value
      end
    end

    private

    def sanitize_value
      require_sanitize do
        self.raw = Sanitize.clean(value, Sanitize::Config::RELAXED)
      end
    end

    def default_value
      if html_type?
        ''.html_safe
      elsif text_type?
        ''
      elsif integer_type?
        0
      elsif yaml_type?
        nil
      elsif phone_type?
        require_russian_phone do
          RussianPhone::Number.new('')
        end
      else
        nil
      end
    end

    def process_text
      replacer = Proc.new do |m|
        if Time.now.strftime('%Y') == $1
          $1
        else
          "#{$1}-#{Time.now.strftime('%Y')}"
        end
      end

      text = raw.dup

      text.gsub!('{{year}}', Time.now.strftime('%Y'))
      text.gsub!(/\{\{year\|([\d]{4})\}\}/, &replacer)
      text = text.html_safe if html_type?
      text
    end

    def load_phone
      require_russian_phone do
        RussianPhone::Number.new(raw)
      end
    end

    def load_yaml
      require_safe_yaml do
        YAML.safe_load(raw)
      end
    end

    def processed_value
      puts "#{type} #{raw}"
      if text_type?
        process_text
      elsif integer_type?
        raw.to_i
      elsif yaml_type?
        load_yaml
      elsif phone_type?
        load_phone
      elsif file_type?
        file.url
      else
        puts "[rails_admin_settings] Unknown field type: #{type}"
        nil<commit_msg>remove debug output<commit_after>module RailsAdminSettings
  module Processing
    def text_type?
      ['string', 'html', 'sanitized', 'email', 'address'].include? type
    end

    def html_type?
      ['html', 'sanitized'].include? type
    end

    def integer_type?
      'integer' == type
    end

    def yaml_type?
      'yaml' == type
    end

    def email_type?
      'email' == type
    end

    def phone_type?
      'phone' == type
    end

    def address_type?
      'address' == type
    end

    def sanitized_type?
      'sanitized' == type
    end

    def file_type?
      'file' == type
    end

    def value
      if file_type?
        file.url
      elsif raw.blank? || disabled?
        default_value
      else
        processed_value
      end
    end

    def to_s
      if yaml_type? || phone_type? || integer_type?
        raw
      else
        value
      end
    end

    private

    def sanitize_value
      require_sanitize do
        self.raw = Sanitize.clean(value, Sanitize::Config::RELAXED)
      end
    end

    def default_value
      if html_type?
        ''.html_safe
      elsif text_type?
        ''
      elsif integer_type?
        0
      elsif yaml_type?
        nil
      elsif phone_type?
        require_russian_phone do
          RussianPhone::Number.new('')
        end
      else
        nil
      end
    end

    def process_text
      replacer = Proc.new do |m|
        if Time.now.strftime('%Y') == $1
          $1
        else
          "#{$1}-#{Time.now.strftime('%Y')}"
        end
      end

      text = raw.dup

      text.gsub!('{{year}}', Time.now.strftime('%Y'))
      text.gsub!(/\{\{year\|([\d]{4})\}\}/, &replacer)
      text = text.html_safe if html_type?
      text
    end

    def load_phone
      require_russian_phone do
        RussianPhone::Number.new(raw)
      end
    end

    def load_yaml
      require_safe_yaml do
        YAML.safe_load(raw)
      end
    end

    def processed_value
      if text_type?
        process_text
      elsif integer_type?
        raw.to_i
      elsif yaml_type?
        load_yaml
      elsif phone_type?
        load_phone
      elsif file_type?
        file.url
      else
        puts "[rails_admin_settings] Unknown field type: #{type}"
        nil
{'fraction_non_alphanumeric': 0.09425690486628671, 'fraction_numerical': 0.0021920210434020165, 'mean_word_length': 1.6284562211981566, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7376377', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1463, 'n_words': 356}