Class: JSONStore
- Inherits:
-
Object
- Object
- JSONStore
- Defined in:
- lib/jsonget.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(options = {}) ⇒ JSONStore
constructor
A new instance of JSONStore.
- #put(host, tmpfile) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ JSONStore
Returns a new instance of JSONStore.
8 9 10 11 12 13 |
# File 'lib/jsonget.rb', line 8 def initialize( = {}) @output_folder = [:prefix] || "." FileUtils.mkdir_p(@output_folder) @parselets = ([:parselets] || []).map{|path| Parsley.new(File.read(path)) } @files = ([:parselets] || []).map{|path| File.open("#{File.basename(path)}.json", "a") } end |
Instance Method Details
#close ⇒ Object
26 27 28 |
# File 'lib/jsonget.rb', line 26 def close @files.map(&:close) end |
#put(host, tmpfile) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/jsonget.rb', line 15 def put(host, tmpfile) @parselets.zip(@files).each do |parselet, file| begin type = (`file "#{tmpfile.path}"` =~ /xml/i) ? :xml : :html output = parselet.parse(:file => tmpfile.path, :input => type, :output => :json) + "," rescue ParsleyError => e STDERR.puts "warning: #{e.}" end end end |