Class: JSONStore

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonget.rb

Instance Method Summary collapse

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(options = {})
  @output_folder = options[:prefix] || "."
  FileUtils.mkdir_p(@output_folder)
  @parselets = (options[:parselets] || []).map{|path| Parsley.new(File.read(path)) }
  @files     = (options[:parselets] || []).map{|path| File.open("#{File.basename(path)}.json", "a") }
end

Instance Method Details

#closeObject



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.message}"
    end
  end
end