class DailyRep::IndexWriter
Public Class Methods
new(index_path=Configer.index_path)
click to toggle source
# File lib/dailyrep/IndexWriter.rb, line 4 def initialize(index_path=Configer.index_path) @out_html_path = index_path.to_s @out_html = Nokogiri::HTML(File.open(@out_html_path)) end
Public Instance Methods
set_html(entity, params, notif=0)
click to toggle source
# File lib/dailyrep/IndexWriter.rb, line 14 def set_html entity, params, notif=0 entity = entity.downcase params.each do |key, val| @out_html.css("##{entity}_#{key}")[0].content = val end @out_html.css("##{entity}_refresh")[0].content = Time.now @out_html.css("##{entity}_notif")[0].content = Time.now if notif == 1 end
set_html_with_diff(entity, scope, diff, reset=false)
click to toggle source
# File lib/dailyrep/IndexWriter.rb, line 23 def set_html_with_diff entity, scope, diff, reset=false entity = entity.downcase target_div = @out_html.css(scope + " .list-group .list-group-item") new_root_node = Nokogiri::XML::Node.new('div', @out_html) new_root_node['class'] = 'list-group' diff.each do |diff_el| target_div.each { |node| if diff_el[0] == '+' && node['href'].include?(diff_el[2].first[0]) then target_div.delete(node) end } end new_root_node.add_child(target_div.unlink) if not reset diff.each do |diff_el| if diff_el[0] == '-' then nodeel = Nokogiri::XML::Node.new('a', @out_html) nodeel['href'] = diff_el[2].first[0] nodeel['class'] = 'list-group-item' nodeel.content = diff_el[2].first[1] new_root_node.add_child(nodeel) end end @out_html.at_css(scope + " .list-group").replace(new_root_node) @out_html.css("##{entity}_refresh")[0].content = Time.now end
write_html()
click to toggle source
# File lib/dailyrep/IndexWriter.rb, line 9 def write_html @out_html.css("#refresh")[0].content = Time.now File.open(@out_html_path , 'w') { |file| file.write(@out_html.to_html) } end