Class: Irasutoya::Category
- Inherits:
-
Object
- Object
- Irasutoya::Category
- Defined in:
- lib/irasutoya/category.rb
Instance Attribute Summary collapse
-
#list_url ⇒ Object
readonly
Returns the value of attribute list_url.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
-
.all ⇒ Object
rubocop:disable Metrics/AbcSize.
Instance Method Summary collapse
- #fetch_irasuto_links ⇒ Object
-
#initialize(title:, list_url:) ⇒ Category
constructor
A new instance of Category.
Methods included from Modules::HasListPageParser
Methods included from Modules::HasDocumentFetcher
Constructor Details
#initialize(title:, list_url:) ⇒ Category
Returns a new instance of Category.
10 11 12 13 |
# File 'lib/irasutoya/category.rb', line 10 def initialize(title:, list_url:) @title = title @list_url = list_url end |
Instance Attribute Details
#list_url ⇒ Object (readonly)
Returns the value of attribute list_url.
8 9 10 |
# File 'lib/irasutoya/category.rb', line 8 def list_url @list_url end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
8 9 10 |
# File 'lib/irasutoya/category.rb', line 8 def title @title end |
Class Method Details
.all ⇒ Object
rubocop:disable Metrics/AbcSize
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/irasutoya/category.rb', line 16 def all # rubocop:disable Metrics/AbcSize fetch_page_and_parse('https://www.irasutoya.com') .css('#sidebar-wrapper') .css('.widget') .select { |w| w.search('h2').text == '詳細カテゴリー' } .first .css('a') .map { |a| a.attribute('href').value } .uniq .select { |href| href.include?('label') } .map { |href| Category.new(title: CGI.unescape(href.split('/')[5]), list_url: href) } end |
Instance Method Details
#fetch_irasuto_links ⇒ Object
30 31 32 33 34 35 |
# File 'lib/irasutoya/category.rb', line 30 def fetch_irasuto_links document = fetch_page_and_parse(list_url) parse_list_page(document: document).map do |parsed| IrasutoLink.new(title: parsed[:title], show_url: parsed[:show_url]) end end |