Class: DsWatcher::Watcher
- Inherits:
-
Object
- Object
- DsWatcher::Watcher
- Defined in:
- lib/ds_watcher.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #coming_soon? ⇒ Boolean
- #get_link(text) ⇒ Object
-
#initialize ⇒ Watcher
constructor
A new instance of Watcher.
- #new_chapter ⇒ Object
- #recent_chapters ⇒ Object
Constructor Details
#initialize ⇒ Watcher
Returns a new instance of Watcher.
8 9 10 11 12 |
# File 'lib/ds_watcher.rb', line 8 def initialize @url = 'https://www.viz.com/shonenjump/chapters/demon-slayer-kimetsu-no-yaiba' @doc = Nokogiri::HTML(open(url)) @text = [] end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
6 7 8 |
# File 'lib/ds_watcher.rb', line 6 def doc @doc end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/ds_watcher.rb', line 6 def url @url end |
Instance Method Details
#coming_soon? ⇒ Boolean
14 15 16 17 18 19 |
# File 'lib/ds_watcher.rb', line 14 def coming_soon? chapter = doc.css('div.type-center.type-sm.line-caption.pad-y-rg.pad-y-md--lg.type-rg--lg:contains("New chapter")') return false unless chapter true end |
#get_link(text) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/ds_watcher.rb', line 46 def get_link(text) if text.include? 'join to read' 'Visit https://www.viz.com/shonenjump/chapters/demon-slayer-kimetsu-no-yaiba to join and read.' else 'https://viz.com' + text end end |
#new_chapter ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ds_watcher.rb', line 21 def new_chapter if coming_soon? coming_soon = doc.css('div.type-center.type-sm.line-caption.pad-y-rg.pad-y-md--lg.type-rg--lg').text.strip! @text << coming_soon else @text << 'Here are some few chapters to re-read: ' @text.join("\n") @text + recent_chapters end end |
#recent_chapters ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ds_watcher.rb', line 33 def recent_chapters doc.css('a.o_chapter-container.disp-bl.color-off-black.hover-off-black.hover-bg-lighter-gray.flex').each do |chapter| date_published = chapter.css('.pad-y-0.pad-r-0.pad-r-rg--sm').text chapter_no = chapter.css('.disp-id.mar-r-sm').text link = get_link(chapter.attribute('href').value) @text << date_published @text << chapter_no @text << link @text.join("\n") end @text end |