Class: Irasutoya::Category

Inherits:
Object
  • Object
show all
Includes:
Modules::HasDocumentFetcher, Modules::HasListPageParser
Defined in:
lib/irasutoya/category.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Modules::HasListPageParser

included

Methods included from Modules::HasDocumentFetcher

included

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_urlObject (readonly)

Returns the value of attribute list_url.



8
9
10
# File 'lib/irasutoya/category.rb', line 8

def list_url
  @list_url
end

#titleObject (readonly)

Returns the value of attribute title.



8
9
10
# File 'lib/irasutoya/category.rb', line 8

def title
  @title
end

Class Method Details

.allObject

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



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