<commit_before>module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
    # The Telecheck object is a plain old Ruby object, similar to Check, and CreditCard.  It supports validation
    # of necessary attributes such as checkholder's name, routing and account numbers, as required by Telecheck but it is
    # not backed by any database.
    # 
    # You may use Telecheck in place of CreditCard with any gateway that supports it. Currently, only
    # +FirstData+ supports the Telecheck object.
    class Telecheck
      include Validateable
      
      attr_accessor :routing, :account, :bankname, :bankstate, :dl, :dlstate, :void,
                    :accounttype, :ssn, :checknumber, :void, :number
      
      def validate
        [:routing, :account, :bankname, :bankstate, :dl, :dlstate].each do |attr|
          errors.add(attr, "cannot be empty") if self.send(attr).blank?
        end

        [:state, :bankstate, :dlstate].each do |state|
          errors.add(state, "must be a valid US State Code") if valid_state_codes.include?(state.to_s)
        end

        errors.add(:routing, "is invalid") unless valid_routing_number?
        
        errors.add(:accounttype, "must be personal or business, checking or savings") if
            !accounttype.blank? && !%w[pc ps bc bs].include?(accounttype.to_s)
      end
      
      def type
        'telecheck'
      end
      
      # Routing numbers may be validated by calculating a checksum and dividing it by 10. The
      # formula is:
      #   (3(d1 + d4 + d7) + 7(d2 + d5 + d8) + 1(d3 + d6 + d9))mod 10 = 0
      # See http://en.wikipedia.org/wiki/Routing_transit_number#Internal_checksums
      def valid_routing_number?
        d = routing.to_s.split('').map(&:to_i).select { |d| (0..9).include?(d) }
        case d.size
          when 9 then
            checksum = ((3 * (d[0] + d[3] + d[6])) +
                        (7 * (d[1] + d[4] + d[7])) +
                             (d[2] + d[5] + d[8])) % 10
            case checksum
              when 0 then true
              else        false
            end
          else false
        end
      end

      def valid_state_codes
        %w[AL AK AZ AR CA CO CT DE DC FL GA HI ID IL IN IA KS KY LA ME MD MA MN MS MO MT NE NV NH NJ NM NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WI WV WY]
      end
    end
  end
end<commit_msg>NY got missed in the list of valid state codes.  I counted, now there are 50 :-)<commit_after>module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
    # The Telecheck object is a plain old Ruby object, similar to Check, and CreditCard.  It supports validation
    # of necessary attributes such as checkholder's name, routing and account numbers, as required by Telecheck but it is
    # not backed by any database.
    # 
    # You may use Telecheck in place of CreditCard with any gateway that supports it. Currently, only
    # +FirstData+ supports the Telecheck object.
    class Telecheck
      include Validateable
      
      attr_accessor :routing, :account, :bankname, :bankstate, :dl, :dlstate, :void,
                    :accounttype, :ssn, :checknumber, :void, :number
      
      def validate
        [:routing, :account, :bankname, :bankstate, :dl, :dlstate].each do |attr|
          errors.add(attr, "cannot be empty") if self.send(attr).blank?
        end

        [:state, :bankstate, :dlstate].each do |state|
          errors.add(state, "must be a valid US State Code") if valid_state_codes.include?(state.to_s)
        end

        errors.add(:routing, "is invalid") unless valid_routing_number?
        
        errors.add(:accounttype, "must be personal or business, checking or savings") if
            !accounttype.blank? && !%w[pc ps bc bs].include?(accounttype.to_s)
      end
      
      def type
        'telecheck'
      end
      
      # Routing numbers may be validated by calculating a checksum and dividing it by 10. The
      # formula is:
      #   (3(d1 + d4 + d7) + 7(d2 + d5 + d8) + 1(d3 + d6 + d9))mod 10 = 0
      # See http://en.wikipedia.org/wiki/Routing_transit_number#Internal_checksums
      def valid_routing_number?
        d = routing.to_s.split('').map(&:to_i).select { |d| (0..9).include?(d) }
        case d.size
          when 9 then
            checksum = ((3 * (d[0] + d[3] + d[6])) +
                        (7 * (d[1] + d[4] + d[7])) +
                             (d[2] + d[5] + d[8])) % 10
            case checksum
              when 0 then true
              else        false
            end
          else false
        end
      end

      def valid_state_codes
        %w[AL AK AZ AR CA CO CT DE DC FL GA HI ID IL IN IA KS KY LA ME MD MA MN MS MO MT NE NV NH NJ NM NC ND NY OH OK OR PA RI SC SD TN TX UT VT VA WA WI WV WY]
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09865940511101802, 'fraction_numerical': 0.01466275659824047, 'mean_word_length': 2.0279010779961952, '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': '6122009', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1460, 'n_words': 546}