Skip to content

Instantly share code, notes, and snippets.

@timruffles
Created November 4, 2011 18:21
Show Gist options
  • Select an option

  • Save timruffles/1340076 to your computer and use it in GitHub Desktop.

Select an option

Save timruffles/1340076 to your computer and use it in GitHub Desktop.
an enviroment for quick shell data munging in xml,html or json
#!/usr/bin/ruby
require "rubygems"
require "nokogiri"
require "json"
format = ARGV[0]
code = ARGV[1]
class Runner
attr_accessor :doc
end
doc = case format
when "json" then JSON.parse(STDIN.read)
when "xml" then Nokogiri::XML(STDIN.read)
when "html" then Nokogiri::HTML(STDIN.read)
end
run = Runner.new
run.doc = doc
run.instance_eval code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment