<commit_before>module JpSki
  # Ski
  class Ski
    attr_accessor :name,
                  :pref,
                  :area,
                  :postal_code,
                  :address,
                  :top,
                  :bottom,
                  :max_slope,
                  :max_angle

    def self.build(args)
      ski = new
      args.each do |k, v|
        ski.instance_variable_set("@#{k}", v) unless v.nil?
      end
      ski
    end

    def self.all
      Mapping.data.map do |ski|
        build(:name => ski[:name], :pref => ski[:pref],
          :area => ski[:area], :postal_code => ski[:postal_code],
          :address => ski[:address], :top => ski[:top], :bottom => ski[:bottom],
          :max_slope => ski[:max_slope], :max_angle => ski[:max_angle])
      end
    end

    def self.find(args)
      return nil unless args.class == Hash

      key = args.keys[0]
      val = args[key]

      case key
      when :name
        return find_by_name(val)
      when :pref
        return find_by_pref(val)
      when :top
        return find_by_top(canonicalize_comparison(val))
      when :bottom
        return find_by_bottom(canonicalize_comparison(val))
      when :max_slope
        return find_by_max_slope(canonicalize_comparison(val))
      when :max_angle
        return find_by_max_angle(canonicalize_comparison(val)) 
      end
      nil
    end

    def self.find_by_name(name)
      data = all.reject do |ski|
        ski.name.downcase !~ /#{name.downcase}/
      end

      return data unless data.empty?
      nil
    end

    def self.find_by_pref(pref)
      data = all.reject do |ski|
        ski.pref != pref
      end

      return data unless data.empty?
      nil
    end

    def self.find_by_top(comparison)
      comparable = comparison[0]
      value = comparison[1]

      data = all.reject do |ski|
        if ski.top.nil?
          true
        else<commit_msg>Refactor<commit_after>module JpSki
  # Ski
  class Ski
    attr_accessor :name,
                  :pref,
                  :area,
                  :postal_code,
                  :address,
                  :top,
                  :bottom,
                  :max_slope,
                  :max_angle

    def self.build(args)
      ski = new
      args.each do |k, v|
        ski.instance_variable_set("@#{k}", v) unless v.nil?
      end
      ski
    end

    def self.all
      Mapping.data.map do |ski|
        build(:name => ski[:name], :pref => ski[:pref],
          :area => ski[:area], :postal_code => ski[:postal_code],
          :address => ski[:address], :top => ski[:top], :bottom => ski[:bottom],
          :max_slope => ski[:max_slope], :max_angle => ski[:max_angle])
      end
    end

    def self.find(args)
      return nil unless args.class == Hash

      key = args.keys[0]
      val = args[key]

      case key
      when :name
        return find_by_name(val)
      when :pref
        return find_by_pref(val)
      when :top
        return find_by_top(canonicalize_comparison(val))
      when :bottom
        return find_by_bottom(canonicalize_comparison(val))
      when :max_slope
        return find_by_max_slope(canonicalize_comparison(val))
      when :max_angle
        return find_by_max_angle(canonicalize_comparison(val))
      end
      nil
    end

    def self.find_by_name(name)
      data = all.reject do |ski|
        ski.name.downcase !~ /#{name.downcase}/
      end

      return data unless data.empty?
      nil
    end

    def self.find_by_pref(pref)
      data = all.reject do |ski|
        ski.pref != pref
      end

      return data unless data.empty?
      nil
    end

    def self.find_by_top(comparison)
      comparable = comparison[0]
      value = comparison[1]

      data = all.reject do |ski|
        if ski.top.nil?
          true
        else
{'fraction_non_alphanumeric': 0.10288713910761155, 'fraction_numerical': 0.0015748031496062992, 'mean_word_length': 1.7105263157894737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '4180331', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1173, 'n_words': 277}