Class: RelatedWord::Service::OnelookService

Inherits:
Object
  • Object
show all
Defined in:
lib/related_word/service/onelook_service.rb

Constant Summary collapse

"http://www.onelook.com/?ws1=1&scwo=1&sswo=0&loc=commonhint&w=*:"
WORD_REGEX =

Regex for filtering words E.g: 1. <a href=“/?loc=rescb&refclue=school&w=academy”>academy</a>

/\d+\.\s<a[^>]+>([a-z\s]+)<\/a>/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(word) ⇒ OnelookService



19
20
21
# File 'lib/related_word/service/onelook_service.rb', line 19

def initialize(word)
  @word = word
end

Instance Attribute Details

#wordObject (readonly)

Returns the value of attribute word.



17
18
19
# File 'lib/related_word/service/onelook_service.rb', line 17

def word
  @word
end

Instance Method Details

#findObject



23
24
25
26
27
28
29
# File 'lib/related_word/service/onelook_service.rb', line 23

def find
  Timeout::timeout(Configure.timeout) do
    resp    = Net::HTTP.get_response(word_uri)
    results = resp.body.scan(WORD_REGEX)
    Formatter::OnelookFormatter.new(results).format
  end
end