Created
November 4, 2011 18:21
-
-
Save timruffles/1340076 to your computer and use it in GitHub Desktop.
an enviroment for quick shell data munging in xml,html or json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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