Class: Irasutoya::Irasuto

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Modules::HasShowPageParser

included

Methods included from Modules::HasListPageParser

included

Methods included from Modules::HasDocumentFetcher

included

Constructor Details

#initialize(url:, title:, description:, image_urls:) ⇒ Irasuto

Returns a new instance of Irasuto.



11
12
13
14
15
16
17
18
19
# File 'lib/irasutoya/irasuto.rb', line 11

def initialize(url:, title:, description:, image_urls:)
  @url = url
  @title = title
  @description = description
  @image_urls = image_urls
  @has_multiple_images = image_urls.size > 1
  @postthumb_image_url = image_urls.first if @has_multiple_images
  @image_url = image_urls.first
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



9
10
11
# File 'lib/irasutoya/irasuto.rb', line 9

def description
  @description
end

#has_multiple_imagesObject (readonly)

Returns the value of attribute has_multiple_images.



9
10
11
# File 'lib/irasutoya/irasuto.rb', line 9

def has_multiple_images
  @has_multiple_images
end

#image_urlObject (readonly)

Returns the value of attribute image_url.



9
10
11
# File 'lib/irasutoya/irasuto.rb', line 9

def image_url
  @image_url
end

#image_urlsObject (readonly)

Returns the value of attribute image_urls.



9
10
11
# File 'lib/irasutoya/irasuto.rb', line 9

def image_urls
  @image_urls
end

#postthumb_image_urlObject (readonly)

Returns the value of attribute postthumb_image_url.



9
10
11
# File 'lib/irasutoya/irasuto.rb', line 9

def postthumb_image_url
  @postthumb_image_url
end

#titleObject (readonly)

Returns the value of attribute title.



9
10
11
# File 'lib/irasutoya/irasuto.rb', line 9

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



9
10
11
# File 'lib/irasutoya/irasuto.rb', line 9

def url
  @url
end

Class Method Details

.randomObject



22
23
24
25
26
27
28
# File 'lib/irasutoya/irasuto.rb', line 22

def random
  url = random_url
  document = fetch_page_and_parse(url)
  parsed = parse_show_page(document: document)

  Irasuto.new(url: url, title: parsed[:title], description: parsed[:description], image_urls: parsed[:image_urls])
end

.search(query:, page: 0) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/irasutoya/irasuto.rb', line 30

def search(query:, page: 0)
  url = if page.zero?
          "https://www.irasutoya.com/search?q=#{CGI.escape query}"
        else
          "https://www.irasutoya.com/search?q=#{CGI.escape query}&max-results=20&start=#{page * 20}&by-date=false"
        end

  document = fetch_page_and_parse(url)
  parse_list_page(document: document).map do |parsed|
    IrasutoLink.new(title: parsed[:title], show_url: parsed[:show_url])
  end
end