class ExactHours::Commands
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/exact_hours/commands.rb, line 10 def initialize(*args) super #@@verbose = true if options[:verbose] end
Public Instance Methods
prepare_for_import(weekfile)
click to toggle source
# File lib/exact_hours/commands.rb, line 21 def prepare_for_import(weekfile) clients_ids = get_clients weekfile year,week_num = get_date_from_weekfile weekfile weekdata = YAML.load_file(weekfile) table = Text::Table.new table.head = ['Account','Date','Employee','Item','Notes','Project','Quantity'] weekdata["days"].each do | day, blocks | blocks.each do | block | table.rows << [clients_ids[block['client']], get_date(year, week_num, day), weekdata['employee'], block['type'],block['note'], block['project'], block['qty']] end end print table.to_s csv_string = CSV.generate force_quotes: false , col_sep: ";" do |csv| table.rows.each do | row | csv << row end end csvfile = File.join File.dirname(weekfile), 'exact_hours.csv' File.open(csvfile, "wb") do |f| f.write(csv_string) end end
version()
click to toggle source
# File lib/exact_hours/commands.rb, line 16 def version print ExactHours::VERSION + "\n" end
Private Instance Methods
get_clients(weekfile)
click to toggle source
# File lib/exact_hours/commands.rb, line 73 def get_clients weekfile clientsfile = File.join File.dirname(weekfile), 'clients' raise "Clients does not exist" unless File.exists? clientsfile vars = {} IO.foreach(clientsfile) do |line| #discard comment lines if line.match(/^#/) next elsif #discard a blank line line.match(/^$/) next else temp = [] temp[0],temp[1] = line.gsub(/\s+/m, ' ').strip.split(" ") vars[temp[1]] = temp[0] end end return vars end
get_date( year, week_num , day)
click to toggle source
# File lib/exact_hours/commands.rb, line 68 def get_date( year, week_num , day) week_start = Date.commercial( year, week_num, DateTime.parse(day).wday ) week_start.strftime( "%d-%m-%Y" ) end
get_date_from_weekfile(weekfile)
click to toggle source
# File lib/exact_hours/commands.rb, line 61 def get_date_from_weekfile(weekfile) p weekfile raise "Week file does not exist" unless File.exists? weekfile arr = File.basename(weekfile).split('.') [arr[1].to_i, arr[2].to_i] end