class Tumblargh::Parser
Attributes
file[R]
Public Class Methods
new(template=nil)
click to toggle source
# File lib/tumblargh/parser.rb, line 20 def initialize(template=nil) self.file = template end
Public Instance Methods
file=(file)
click to toggle source
# File lib/tumblargh/parser.rb, line 26 def file=(file) @file = file @html = nil @structure = nil @tree = nil @config = nil end
html()
click to toggle source
# File lib/tumblargh/parser.rb, line 39 def html @html ||= open(@file).read end
html=(html)
click to toggle source
# File lib/tumblargh/parser.rb, line 34 def html=(html) self.file = nil @html = html end
options()
click to toggle source
# File lib/tumblargh/parser.rb, line 47 def options @options ||= extract_options end
to_s()
click to toggle source
# File lib/tumblargh/parser.rb, line 51 def to_s parse unless @structure @structure.to_s end
tree()
click to toggle source
# File lib/tumblargh/parser.rb, line 43 def tree @tree ||= parse end
Private Instance Methods
extract_options()
click to toggle source
# File lib/tumblargh/parser.rb, line 68 def extract_options opts = {}.with_indifferent_access doc = Nokogiri::HTML(html) doc.css('meta[name*=":"]').each do |meta| type, variable = meta['name'].downcase.split(':') variable.gsub!(/\s/, '') default = meta['content'] default = case type when "if" default == "1" else default end opts[type] ||= {} opts[type][variable] = default end opts end
parse()
click to toggle source
# File lib/tumblargh/parser.rb, line 58 def parse @structure = @@parser.parse(html) if @structure.nil? raise ParserError, @@parser.failure_reason end @tree = @structure.to_tree end