Class: NcodeSyosetu::Model::Episode
- Inherits:
-
Object
- Object
- NcodeSyosetu::Model::Episode
- Defined in:
- lib/ncode_syosetu/model/episode.rb
Instance Attribute Summary collapse
-
#body_html ⇒ Object
Returns the value of attribute body_html.
-
#number ⇒ Object
Returns the value of attribute number.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #html ⇒ Object
-
#initialize(title, number, page) ⇒ Episode
constructor
A new instance of Episode.
- #markdown ⇒ Object
- #text ⇒ Object
Constructor Details
#initialize(title, number, page) ⇒ Episode
Returns a new instance of Episode.
9 10 11 12 13 14 15 16 17 |
# File 'lib/ncode_syosetu/model/episode.rb', line 9 def initialize(title, number, page) @url = page.uri.to_s @title = title @number = number @body_html = page.search(".p-novel__title").to_html << page.search(".p-novel__body").to_html end |
Instance Attribute Details
#body_html ⇒ Object
Returns the value of attribute body_html.
7 8 9 |
# File 'lib/ncode_syosetu/model/episode.rb', line 7 def body_html @body_html end |
#number ⇒ Object
Returns the value of attribute number.
7 8 9 |
# File 'lib/ncode_syosetu/model/episode.rb', line 7 def number @number end |
#title ⇒ Object
Returns the value of attribute title.
7 8 9 |
# File 'lib/ncode_syosetu/model/episode.rb', line 7 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/ncode_syosetu/model/episode.rb', line 7 def url @url end |
Instance Method Details
#html ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ncode_syosetu/model/episode.rb', line 19 def html "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"ja\" lang=\"ja\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n<title>\#{@title}</title>\n</head>\n<body>\n\n\#{@body_html}\n\n</body>\n</html>\n HTML\nend\n" |
#markdown ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ncode_syosetu/model/episode.rb', line 47 def markdown doc = Nokogiri::HTML.fragment(@body_html) lines = [] title_text = doc.at(".p-novel__title")&.text&.strip lines << "## #{title_text}" if title_text lines << "" doc.search(".p-novel__text p").each do |p| lines << ruby_to_markdown(p) end lines.join("\n") end |
#text ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/ncode_syosetu/model/episode.rb', line 37 def text doc = Nokogiri::HTML.fragment(@body_html) lines = [] lines << doc.at(".p-novel__title")&.text&.strip doc.search(".p-novel__text p").each do |p| lines << p.text end lines.compact.join("\n") end |