Class not found error when calling a module::class method

I’m working on a module to automate the creation of ebooks. When trying
to call a method like in the class below:

#!/usr/bin/env ruby -w

require_relative ‘…/lib/ctools/validator.rb’

class Tool_test

p $LOAD_PATH

@html =
File.new(‘/Users/carlos/experiment/code/ctools/test/index.html’).read

p @html

Ctools::Validator.check_html(@html)
end

I get the following error:

undefined method `check_html’ for Ctools::Validator:Class
(NoMethodError)

The method is there. The class that is referenced by Tool_test is as
follows:

#!/usr/bin/env ruby -w
require ‘json’
require ‘rest_client’

module Ctools
class Validator

Based on the code from

attr_reader :errors
BASE_URI = 'http://html5.validator.nu'
HEADERS = { 'Content-Type' => 'text/html; charset=utf-8',

‘Content-Encoding’ => ‘UTF-8’ }

def initialize(proxy = nil)
  RestClient.proxy = proxy unless proxy.nil?
end

# Validate the markup of a String
def check_html(text)
  response = RestClient.post "#{BASE_URI}/?out=json", text, HEADERS
  @json = JSON.parse(response.body)
  @errors = retrieve_errors
end

# Validate the markup of a URI
def validate_uri(uri)
  response = RestClient.get BASE_URI, :params => { :doc => uri, :out

=> ‘json’ }
@json = JSON.parse(response.body)
@errors = retrieve_errors
end

def inspect
@errors.map do |err|
  "- Error: #{err['message']}"
  end.join("\n")
end

def valid?
  @errors.length == 0
end

private

def retrieve_errors
  @json['messages'].select { |mssg| mssg['type'] == 'error' }
end

end #class
end # module

Any pointers as to what’s causing the error are appreciated. I am using
ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-darwin11.4.0] on OS X
10.7

On Jul 18, 2012, at 17:14 , Carlos Araya wrote:

undefined method `check_html’ for Ctools::Validator:Class
(NoMethodError)

The method is there. The class that is referenced by Tool_test is as
follows:

The method is NOT there. You’re calling an instance method as a class
method. Wrong object == method_missing.

You need to call instance methods with instances of the class.
Instantiate a Validator and it will work.

I changed Tool_test to the following:

#!/usr/bin/env ruby -w

require_relative ‘…/lib/ctools/validator.rb’

class Tool_test

p $LOAD_PATH

@html =
File.new(’/Users/carlos/experiment/code/ctools/test/index.html’).read

p @html

check = Ctools::Validator.new
check.validate_text(@html)
end

but it still gives me the same error

./bin/validate_test.rb:10:in <class:Tool_test>': undefined methodvalidate_text’ for :Ctools::Validator (NoMethodError)
from ./bin/validate_test.rb:5:in `’

I’ve also tried removing the Tool_test class to make sure that is not
the source of the error.

Am I instantiating the class correctly?

Thanks, that solved the problem.

I instantiated the class using check = Ctools::Validator.new

and then just called check.check_html

Thanks

according to your first code, the method is check_html