Class: Lecture7::Search
- Inherits:
-
Object
- Object
- Lecture7::Search
- Defined in:
- lib/lecture7/search.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Search
constructor
A new instance of Search.
- #movies ⇒ Object
- #search_on_url(url) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Search
Returns a new instance of Search.
6 7 8 9 |
# File 'lib/lecture7/search.rb', line 6 def initialize( = {}) @url = [:url] @pattern = [:pattern] end |
Instance Attribute Details
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
4 5 6 |
# File 'lib/lecture7/search.rb', line 4 def pattern @pattern end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
4 5 6 |
# File 'lib/lecture7/search.rb', line 4 def url @url end |
Instance Method Details
#movies ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/lecture7/search.rb', line 11 def movies if url search_on_url(url) else [] end end |
#search_on_url(url) ⇒ Object
19 20 21 22 23 |
# File 'lib/lecture7/search.rb', line 19 def search_on_url(url) agent = Mechanize.new page = agent.get(url) page.links_with(pattern).map(&:text) end |