Class: NiwaTextream::TopPage
- Defined in:
- lib/niwa_textream/pages/top/top_page.rb
Overview
Textream’s top page (textream.yahoo.co.jp/)
Constant Summary collapse
- @@url =
"http://textream.yahoo.co.jp/"
Instance Attribute Summary collapse
-
#categories ⇒ Object
Returns the value of attribute categories.
Attributes inherited from MainPage
Instance Method Summary collapse
-
#clickCategory(name) ⇒ Object
click category.
-
#initialize(mechanize) ⇒ TopPage
constructor
A new instance of TopPage.
-
#set_categories ⇒ Object
search categories mechanize objects.
Methods inherited from MainPage
Constructor Details
#initialize(mechanize) ⇒ TopPage
Returns a new instance of TopPage.
11 12 13 14 |
# File 'lib/niwa_textream/pages/top/top_page.rb', line 11 def initialize(mechanize) super(mechanize) set_categories end |
Instance Attribute Details
#categories ⇒ Object
Returns the value of attribute categories.
7 8 9 |
# File 'lib/niwa_textream/pages/top/top_page.rb', line 7 def categories @categories end |
Instance Method Details
#clickCategory(name) ⇒ Object
click category.
-
name
- category name(string)
return: CategoryPage (If you click this link, you will move to CategoryPage)
35 36 37 38 |
# File 'lib/niwa_textream/pages/top/top_page.rb', line 35 def clickCategory(name) @mechanize.click(@categories[name].elem) return NiwaTextream::CategoryPage.new(@mechanize) end |
#set_categories ⇒ Object
search categories mechanize objects
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/niwa_textream/pages/top/top_page.rb', line 17 def set_categories @categories = {} @mechanize.page.search('//*[@id="prtcalst"]//li').each do |cat| cat_link = cat.search('a')[0] cat_name = cat.search('.//em')[0].inner_text() catObj = Category.new() catObj.elem = cat_link catObj.name = cat_name @categories[cat_name] = catObj puts("#{cat_name}") puts("-------------------") end end |