Class: Irasutoya::Irasuto
- Inherits:
-
Object
- Object
- Irasutoya::Irasuto
- Defined in:
- lib/irasutoya/irasuto.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#has_multiple_images ⇒ Object
readonly
Returns the value of attribute has_multiple_images.
-
#image_url ⇒ Object
readonly
Returns the value of attribute image_url.
-
#image_urls ⇒ Object
readonly
Returns the value of attribute image_urls.
-
#postthumb_image_url ⇒ Object
readonly
Returns the value of attribute postthumb_image_url.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(url:, title:, description:, image_urls:) ⇒ Irasuto
constructor
A new instance of Irasuto.
Methods included from Modules::HasShowPageParser
Methods included from Modules::HasListPageParser
Methods included from Modules::HasDocumentFetcher
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
#description ⇒ Object (readonly)
Returns the value of attribute description.
9 10 11 |
# File 'lib/irasutoya/irasuto.rb', line 9 def description @description end |
#has_multiple_images ⇒ Object (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_url ⇒ Object (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_urls ⇒ Object (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_url ⇒ Object (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 |
#title ⇒ Object (readonly)
Returns the value of attribute title.
9 10 11 |
# File 'lib/irasutoya/irasuto.rb', line 9 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
9 10 11 |
# File 'lib/irasutoya/irasuto.rb', line 9 def url @url end |
Class Method Details
.random ⇒ Object
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 |