class MaxML::XML
Attributes
date[R]
db[RW]
url[R]
Public Class Methods
fetch_content(url)
click to toggle source
# File lib/maxml/xml.rb, line 41 def self.fetch_content(url) uri = URI.parse(url) uri.read end
new(url, db=MongoPersistence, **db_conf)
click to toggle source
# File lib/maxml/xml.rb, line 11 def initialize(url, db=MongoPersistence, **db_conf) @url = url @date = Time.now @content = self.class.fetch_content(url) @db = db.new db_config(db_conf) unless db_conf.empty? end
Public Instance Methods
db_config(opts)
click to toggle source
# File lib/maxml/xml.rb, line 37 def db_config(opts) @db.config = opts end
save() { |to_hash| ... }
click to toggle source
# File lib/maxml/xml.rb, line 32 def save content = block_given? ? yield(to_hash) : to_hash @db.save({url: @url, date: @date, content: content}) end
to_hash()
click to toggle source
# File lib/maxml/xml.rb, line 27 def to_hash parser = Nori.new parser.parse(@content) end
to_json()
click to toggle source
# File lib/maxml/xml.rb, line 23 def to_json to_hash.to_json end
to_s()
click to toggle source
# File lib/maxml/xml.rb, line 19 def to_s @content end