class MessengerPigeon::CSV::Source
Source
definition
Public Class Methods
new(options)
click to toggle source
# File lib/messenger_pigeon/modules/csv.rb, line 8 def initialize(options) # :file_glob @files = Dir.glob(File.expand_path options[:file_glob]) @on_complete = options[:on_complete] end
Public Instance Methods
complete()
click to toggle source
# File lib/messenger_pigeon/modules/csv.rb, line 18 def complete case @on_complete when :archive archive_files end end
read()
click to toggle source
# File lib/messenger_pigeon/modules/csv.rb, line 14 def read @files.collect { |f| read_file f }.flatten end
Private Instance Methods
archive_files()
click to toggle source
# File lib/messenger_pigeon/modules/csv.rb, line 27 def archive_files @files.each do |f| archive_dir = (File.dirname f) + '/archive/' Dir.mkdir archive_dir unless Dir.exist? archive_dir File.rename(f, archive_dir + (File.basename f)) if File.exist? f end end
read_file(file)
click to toggle source
# File lib/messenger_pigeon/modules/csv.rb, line 35 def read_file(file) d = CSVLib.read file headings = d.first.collect do |v| title = v.gsub(/[^a-z]+/i, '_') title.downcase.intern end d[1..-1].collect { |v| (headings.zip v).to_h } end