Class: EverExp::Html
- Inherits:
-
Object
- Object
- EverExp::Html
- Defined in:
- lib/ever_exp/html.rb,
lib/ever_exp/heading.rb
Defined Under Namespace
Classes: Heading
Instance Attribute Summary collapse
-
#html ⇒ Object
readonly
Returns the value of attribute html.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#note ⇒ Object
writeonly
Sets the attribute note.
Instance Method Summary collapse
- #attachments ⇒ Object
- #code_blocks ⇒ Object
- #content ⇒ Object
- #created ⇒ Object
- #heading ⇒ Object
- #heading? ⇒ Boolean
- #heading_elements ⇒ Object
- #imgs ⇒ Object
-
#initialize(path) ⇒ Html
constructor
A new instance of Html.
- #isHtml? ⇒ Boolean
- #name ⇒ Object
- #tags ⇒ Object
- #tags_array ⇒ Object
- #title ⇒ Object
- #updated ⇒ Object
Constructor Details
#initialize(path) ⇒ Html
Returns a new instance of Html.
11 12 13 14 |
# File 'lib/ever_exp/html.rb', line 11 def initialize path @html = File.open(path) { |f| Nokogiri::HTML(f) } @location = path end |
Instance Attribute Details
#html ⇒ Object (readonly)
Returns the value of attribute html.
8 9 10 |
# File 'lib/ever_exp/html.rb', line 8 def html @html end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
8 9 10 |
# File 'lib/ever_exp/html.rb', line 8 def location @location end |
#note=(value) ⇒ Object (writeonly)
Sets the attribute note
9 10 11 |
# File 'lib/ever_exp/html.rb', line 9 def note=(value) @note = value end |
Instance Method Details
#attachments ⇒ Object
57 58 59 60 61 |
# File 'lib/ever_exp/html.rb', line 57 def _content. css('a'). select{|a| a.css('img').count > 0} end |
#code_blocks ⇒ Object
47 48 49 50 51 |
# File 'lib/ever_exp/html.rb', line 47 def code_blocks html. css('div'). select { |div| div.attr('style') =~ /^-en-codeblock/ } end |
#content ⇒ Object
63 64 65 |
# File 'lib/ever_exp/html.rb', line 63 def content _content.to_html end |
#created ⇒ Object
37 38 39 40 |
# File 'lib/ever_exp/html.rb', line 37 def created @created end |
#heading ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/ever_exp/html.rb', line 71 def heading return @heading if @heading h = Heading.new heading_elements.each do |b| level, title = level_title b h.add level, title end @heading = h.to_h end |
#heading? ⇒ Boolean
67 68 69 |
# File 'lib/ever_exp/html.rb', line 67 def heading? not heading.empty? end |
#heading_elements ⇒ Object
81 82 83 |
# File 'lib/ever_exp/html.rb', line 81 def heading_elements _content.css('div > b, div > span > b') end |
#imgs ⇒ Object
53 54 55 |
# File 'lib/ever_exp/html.rb', line 53 def imgs html.css('img') end |
#isHtml? ⇒ Boolean
20 21 22 |
# File 'lib/ever_exp/html.rb', line 20 def isHtml? true end |
#name ⇒ Object
16 17 18 |
# File 'lib/ever_exp/html.rb', line 16 def name File.basename(location).gsub(/\.html$/, '') end |
#tags ⇒ Object
28 29 30 31 |
# File 'lib/ever_exp/html.rb', line 28 def @tags end |
#tags_array ⇒ Object
33 34 35 |
# File 'lib/ever_exp/html.rb', line 33 def .split ', ' end |
#title ⇒ Object
24 25 26 |
# File 'lib/ever_exp/html.rb', line 24 def title @title ||= html.title end |
#updated ⇒ Object
42 43 44 45 |
# File 'lib/ever_exp/html.rb', line 42 def updated @updated end |