<commit_before>require 'json'

module Razorpay
  class IFSC
    def self.data
      @data ||= JSON.load(File.read(File.join(__dir__, '../../IFSC.json')))
    end

    def self.validate(code)
      return false unless code.size == 11
      return false unless code[4] == '0'

      bank_code = code[0..3].upcase
      branch_code = code[4..-1].upcase

      return false unless data.has_key? bank_code

      list = data[bank_code]

      # puts "#{code} - " + (code =~ /[0-9]/)

      if (code =~ /[0-9]/)
        self.lookup_numeric(list, branch_code)
      else
        self.lookup_string(list, branch_code)
      end
    end

    def self.lookup_numeric(list, branch_code)
      branch_code = branch_code.to_i

      return true if list.include? branch_code

      lookup_ranges list, branch_code
    end

    def self.lookup_ranges(list, branch_code)
      list.each do |item|
        return false unless item.is_a?(Array) && item.size == 2

        (item[0]...item[1]) === branch_code
      end<commit_msg>[ruby] Fix string lookup<commit_after>require 'json'

module Razorpay
  class IFSC
    def self.data
      @data ||= JSON.load(File.read(File.join(__dir__, '../../IFSC.json')))
    end

    def self.validate(code)
      return false unless code.size == 11
      return false unless code[4] == '0'

      bank_code = code[0..3].upcase
      branch_code = code[5..-1].upcase

      return false unless data.has_key? bank_code

      list = data[bank_code]

      if (branch_code.match(/^(\d)+$/))
        self.lookup_numeric(list, branch_code)
      else
        self.lookup_string(list, branch_code)
      end
    end

    def self.lookup_numeric(list, branch_code)
      branch_code = branch_code.to_i

      return true if list.include? branch_code

      lookup_ranges list, branch_code
    end

    def self.lookup_ranges(list, branch_code)
      list.each do |item|
        return false unless item.is_a?(Array) && item.size == 2

        (item[0]...item[1]) === branch_code
      end
{'fraction_non_alphanumeric': 0.12456228114057029, 'fraction_numerical': 0.013006503251625813, 'mean_word_length': 2.395585738539898, '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': '74333', 'n_tokens_mistral': 683, 'n_tokens_neox': 656, 'n_words': 153}