Class: Asciibook::Page
- Inherits:
-
Object
- Object
- Asciibook::Page
- Defined in:
- lib/asciibook/page.rb
Instance Attribute Summary collapse
-
#footnotes ⇒ Object
Returns the value of attribute footnotes.
-
#next_page ⇒ Object
Returns the value of attribute next_page.
-
#node ⇒ Object
Returns the value of attribute node.
-
#path ⇒ Object
Returns the value of attribute path.
-
#prev_page ⇒ Object
Returns the value of attribute prev_page.
Instance Method Summary collapse
- #content ⇒ Object
- #description ⇒ Object
- #doc ⇒ Object
- #image_url ⇒ Object
-
#initialize(path:, node:) ⇒ Page
constructor
A new instance of Page.
- #outline ⇒ Object
-
#outline_node(node) ⇒ Object
page outline only list sections that not split as page.
- #title ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(path:, node:) ⇒ Page
Returns a new instance of Page.
5 6 7 8 9 10 |
# File 'lib/asciibook/page.rb', line 5 def initialize(path:, node:) @path = path @node = node @footnotes = [] end |
Instance Attribute Details
#footnotes ⇒ Object
Returns the value of attribute footnotes.
3 4 5 |
# File 'lib/asciibook/page.rb', line 3 def footnotes @footnotes end |
#next_page ⇒ Object
Returns the value of attribute next_page.
3 4 5 |
# File 'lib/asciibook/page.rb', line 3 def next_page @next_page end |
#node ⇒ Object
Returns the value of attribute node.
3 4 5 |
# File 'lib/asciibook/page.rb', line 3 def node @node end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/asciibook/page.rb', line 3 def path @path end |
#prev_page ⇒ Object
Returns the value of attribute prev_page.
3 4 5 |
# File 'lib/asciibook/page.rb', line 3 def prev_page @prev_page end |
Instance Method Details
#content ⇒ Object
16 17 18 |
# File 'lib/asciibook/page.rb', line 16 def content @content ||= node.convert end |
#description ⇒ Object
28 29 30 |
# File 'lib/asciibook/page.rb', line 28 def description doc.css('p').first&.text end |
#doc ⇒ Object
20 21 22 |
# File 'lib/asciibook/page.rb', line 20 def doc @doc ||= Nokogiri::HTML.fragment(content) end |
#image_url ⇒ Object
24 25 26 |
# File 'lib/asciibook/page.rb', line 24 def image_url doc.css('img').first&.attr('src') end |
#outline ⇒ Object
32 33 34 |
# File 'lib/asciibook/page.rb', line 32 def outline outline_node(@node) end |
#outline_node(node) ⇒ Object
page outline only list sections that not split as page
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/asciibook/page.rb', line 37 def outline_node(node) data = [] node.sections.each do |section| if !section.page section_data = { 'title' => section.xreftext, 'path' => "##{section.id}" } if section.sections.count > 0 section_data['items'] = outline_node(section) end data << section_data end end data end |
#title ⇒ Object
12 13 14 |
# File 'lib/asciibook/page.rb', line 12 def title node.title end |
#to_hash ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/asciibook/page.rb', line 54 def to_hash { 'path' => path, 'title' => title, 'content' => content, 'image_url' => image_url, 'description' => description, 'outline' => outline, 'prev_page' => prev_page && { 'path' => prev_page.path, 'title' => prev_page.title }, 'next_page' => next_page && { 'path' => next_page.path, 'title' => next_page.title } } end |