D
Danny Tatom
I'm terribly confused with this, and can't seem to figure it out (or
explain it).
Using HTTParty, I have a method that grabs some XML and returns it as a
hash:
def check(data)
@results = self.class.post('/checkDocument', :query => {:key =>
@key,
:data => data})
end
def errors
errors = @results['results']['error']
end
An example of the hash it returns:=> [{"suggestions"=>{"option"=>["really", "ready", "real", "relay",
"realty"]}, "precontext"=>"I'm", "type"=>"spelling", "string"=>"realy",
"description"=>"Spelling"}, {"suggestions"=>{"option"=>["weather",
"whether"]},
"url"=>"http://service.afterthedeadline.com/info.slp?text=wether",
"precontext"=>"this", "type"=>"spelling", "string"=>"wether",
"description"=>"Did you mean..."}]
Now calling the .errors method, I can get the string from each one like
this:
"wether"
What I'd like to do is write a method for string, so that
atd.errors.each { |error| p.error.string } would result in the same
thing. For the life of me, I can't figure out how to do that. :/
The other problem I'm having with the way I'm doing it now is that
calling .errors.each when there's only one error sent back gives me a
"can't convert String into Integer" error.
So, if anyone could point me in the right direction, I'd appreciate it.
explain it).
Using HTTParty, I have a method that grabs some XML and returns it as a
hash:
def check(data)
@results = self.class.post('/checkDocument', :query => {:key =>
@key,
:data => data})
end
def errors
errors = @results['results']['error']
end
An example of the hash it returns:=> [{"suggestions"=>{"option"=>["really", "ready", "real", "relay",
"realty"]}, "precontext"=>"I'm", "type"=>"spelling", "string"=>"realy",
"description"=>"Spelling"}, {"suggestions"=>{"option"=>["weather",
"whether"]},
"url"=>"http://service.afterthedeadline.com/info.slp?text=wether",
"precontext"=>"this", "type"=>"spelling", "string"=>"wether",
"description"=>"Did you mean..."}]
Now calling the .errors method, I can get the string from each one like
this:
"realy"atd.errors.each { |error| p error['string'] }
"wether"
What I'd like to do is write a method for string, so that
atd.errors.each { |error| p.error.string } would result in the same
thing. For the life of me, I can't figure out how to do that. :/
The other problem I'm having with the way I'm doing it now is that
calling .errors.each when there's only one error sent back gives me a
"can't convert String into Integer" error.
So, if anyone could point me in the right direction, I'd appreciate it.