lib/papercall/file_fetcher.rb in papercall-0.15.2 vs lib/papercall/file_fetcher.rb in papercall-1.0.0

- old
+ new

@@ -1,27 +1,30 @@ require 'json' +require 'papercall/models/submission' +require 'active_support/core_ext/hash/indifferent_access' module Papercall # Fetches submissions from file. # Params: # +filename+:: File with submissions. JSON format. class FileFetcher < Fetcher - def initialize(filename) - @filename = filename + def initialize() + @output = Papercall.configuration.output + @filename = Papercall.configuration.input_file @submitted = [] @accepted = [] @rejected = [] @waitlist = [] @declined = [] end def fetch(_) file = File.new(@filename, 'r') - puts "Reading from file (#{file.path})..." - submissions = JSON.parse file.read if file - @submitted = submissions['submitted'] - @accepted = submissions['accepted'] - @rejected = submissions['rejected'] - @waitlist = submissions['waitlist'] + puts 'Reading from file (#{file.path})...' if @output + submissions = JSON.parse(file.read).with_indifferent_access if file + @submitted = submissions[:submitted].map {|s| Submission.new(s)} + @accepted = submissions[:accepted].map {|s| Submission.new(s)} + @rejected = submissions[:rejected].map {|s| Submission.new(s)} + @waitlist = submissions[:waitlist].map {|s| Submission.new(s)} end end end