Skip to content

Instantly share code, notes, and snippets.

@manveru
Created June 27, 2011 13:12
Show Gist options
  • Save manveru/1048826 to your computer and use it in GitHub Desktop.
Save manveru/1048826 to your computer and use it in GitHub Desktop.
tracking changes over time, simple example
require 'open-uri'
require 'yaml/store'
require 'nokogiri'
doc = Nokogiri(open('http://namebit.org'))
current = doc.at('#blocks_found').text.to_i
YAML::Store.new('namebit.yaml').transaction do |store|
if previous = store[:previous]
case current <=> previous
when 1
puts "It increased! Up from #{previous} to #{current}"
when 0
puts "No change, it's still #{current}"
when -1
puts "It decreased! Down from #{previous} to #{current}"
end
else
puts "First time, it's at #{current} right now"
end
store[:previous] = current
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment