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