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
- #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
- #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
#code_blocks ⇒ Object
43 44 45 46 47 |
# File 'lib/ever_exp/html.rb', line 43 def code_blocks html. css('div'). select { |div| div.attr('style') =~ /^-en-codeblock/ } end |
#content ⇒ Object
53 54 55 |
# File 'lib/ever_exp/html.rb', line 53 def content _content.to_html end |
#created ⇒ Object
33 34 35 36 |
# File 'lib/ever_exp/html.rb', line 33 def created @created end |
#heading ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/ever_exp/html.rb', line 61 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
57 58 59 |
# File 'lib/ever_exp/html.rb', line 57 def heading? not heading.empty? end |
#heading_elements ⇒ Object
71 72 73 |
# File 'lib/ever_exp/html.rb', line 71 def heading_elements _content.css('div > b, div > span > b') end |
#imgs ⇒ Object
49 50 51 |
# File 'lib/ever_exp/html.rb', line 49 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 |
#title ⇒ Object
24 25 26 |
# File 'lib/ever_exp/html.rb', line 24 def title @title ||= html.title end |
#updated ⇒ Object
38 39 40 41 |
# File 'lib/ever_exp/html.rb', line 38 def updated @updated end |