Class: RelatedWord::Service::OnelookService
- Inherits:
-
Object
- Object
- RelatedWord::Service::OnelookService
- Defined in:
- lib/related_word/service/onelook_service.rb
Constant Summary collapse
- LINK =
"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
-
#word ⇒ Object
readonly
Returns the value of attribute word.
Instance Method Summary collapse
- #find ⇒ Object
-
#initialize(word) ⇒ OnelookService
constructor
A new instance of OnelookService.
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
#word ⇒ Object (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
#find ⇒ Object
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 |