class EverExp::Html
Attributes
html[R]
location[R]
note[W]
Public Class Methods
new(path)
click to toggle source
# File lib/ever_exp/html.rb, line 11 def initialize path @html = File.open(path) { |f| Nokogiri::HTML(f) } @location = path end
Public Instance Methods
attachments()
click to toggle source
# File lib/ever_exp/html.rb, line 57 def attachments _content. css('a'). select{|a| a.css('img').count > 0} end
code_blocks()
click to toggle source
# File lib/ever_exp/html.rb, line 47 def code_blocks html. css('div'). select { |div| div.attr('style') =~ /^-en-codeblock/ } end
content()
click to toggle source
# File lib/ever_exp/html.rb, line 63 def content _content.to_html end
created()
click to toggle source
# File lib/ever_exp/html.rb, line 37 def created parse_meta @created end
heading()
click to toggle source
# 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?()
click to toggle source
# File lib/ever_exp/html.rb, line 67 def heading? not heading.empty? end
heading_elements()
click to toggle source
# File lib/ever_exp/html.rb, line 81 def heading_elements _content.css('div > b, div > span > b') end
imgs()
click to toggle source
# File lib/ever_exp/html.rb, line 53 def imgs html.css('img') end
isHtml?()
click to toggle source
# File lib/ever_exp/html.rb, line 20 def isHtml? true end
name()
click to toggle source
# File lib/ever_exp/html.rb, line 16 def name File.basename(location).gsub(/\.html$/, '') end
title()
click to toggle source
# File lib/ever_exp/html.rb, line 24 def title @title ||= html.title end
updated()
click to toggle source
# File lib/ever_exp/html.rb, line 42 def updated parse_meta @updated end
Private Instance Methods
_content()
click to toggle source
# File lib/ever_exp/html.rb, line 93 def _content return @_content if defined? @_content @_content = html.css('body > div').last return @_content unless breakword = @_content.css('div').select{|n| n['style'] =~ /break-word/}[0] breakword.children.each{|c| c.parent = breakword.parent} breakword.remove @_content end
level_title(bold_tag)
click to toggle source
# File lib/ever_exp/html.rb, line 87 def level_title bold_tag level = (bold_tag.parent.name == 'span' ? bold_tag.parent.attr('style').gsub(/[^\d]/, '') : '1') title = bold_tag.text [level, title] end
meta()
click to toggle source
# File lib/ever_exp/html.rb, line 113 def meta @meta ||= html.at_css 'table' end
meta_value(tr)
click to toggle source
# File lib/ever_exp/html.rb, line 117 def meta_value tr tr.css('td').last.at_css('i').text end
parse_date(date)
click to toggle source
# File lib/ever_exp/html.rb, line 121 def parse_date date date_arr = date.split(/\s+/) ymd, hmin = date_arr.first, date_arr.last y, m, d = ymd.split('/') h, min = hmin.split(':') Time.new y, m, d, h, min end
parse_meta()
click to toggle source
# File lib/ever_exp/html.rb, line 102 def parse_meta return if @parsed_meta metas = meta.css('tr') raise IOError, 'meta is broken' if metas.size < 2 @created = parse_date meta_value metas[0] @updated = parse_date meta_value metas[1] @tags = meta_value metas[2] @tags = meta_value metas[3] if @tags =~ /@/ @parsed_meta = true end