class Urban::Dictionary
Constants
- Entry
Attributes
web_service[W]
Public Instance Methods
random()
click to toggle source
# File lib/urban/dictionary.rb, line 10 def random process(web_service.random) end
search(phrase)
click to toggle source
# File lib/urban/dictionary.rb, line 14 def search(phrase) process(web_service.search(phrase)) end
web_service()
click to toggle source
# File lib/urban/dictionary.rb, line 18 def web_service @web_service ||= Urban::Web.new end
Private Instance Methods
parse_definitions(document)
click to toggle source
# File lib/urban/dictionary.rb, line 37 def parse_definitions(document) document.xpath('//div[@class="meaning"]').map do |node| node.xpath("//br").each { |br| br.replace(Nokogiri::XML::Text.new("\n", node.document)) }; node.content.strip end end
process(response)
click to toggle source
# File lib/urban/dictionary.rb, line 24 def process(response) document = Nokogiri::HTML(response.stream) if not_defined = document.at_xpath('//div[@id="not_defined_yet"]/h1/i') Entry.new(not_defined.content.strip, nil, nil) else Entry.new( document.at_xpath('//div/a[@class="word"][1]').content.strip, parse_definitions(document), response.url ) end end