RUBY: Validate chemical identifiers

class Chemical_ID

# Getters and setters
########################################################
	attr_accessor :state

# Method - Initialize
########################################################
	
	def initialize
		@cas_number = cas_number
		@ec_number = ec_number
	
	 p "this is the init..."
	end

# Method to validate CAS numbers by checksum
########################################################

	def cas_validate(cas_number)
	  return false unless cas_number && cas_number.match(/[0-9]{2,7}-[0-9]{2}-[0-9]/)
	    check_digit = cas_number[-1,1].to_i
	    sum = 0
	    cas_number.reverse.scan(/[0-9]/).each_with_index do |digit, i|
	    sum = sum + digit.to_i * i
	  end
	  check_digit == sum.remainder(10)

# Method to validate EC numbers by checksum     
########################################################

	def ec_validate(ec_number)
	  return false unless ec_number && ec_number.match(/[0-9]{3}-[0-9]{3}-[0-9]/)
	    check_digit = ec_number[-1,1].to_i
	    sum = 0
	    ec_number.reverse.scan(/[0-9]/).each_with_index do |digit, i|
	    sum = sum + digit.to_i * i
	  end
	  check_digit == sum.remainder(11)
	end

end

"Is this a ... what day is this?"