Class: BBNW::CsvFile

Inherits:
Object
  • Object
show all
Includes:
Activities, DateTimeUtils
Defined in:
lib/adapters/csv_file.rb

Instance Attribute Summary

Attributes included from Activities

#activities

Instance Method Summary collapse

Methods included from DateTimeUtils

#is_number?, #long_date, #long_date_time, #long_time, #parse_time, #short_date, #short_time, #time_description

Constructor Details

#initialize(file_path, columns = [0,1,2], debug = false) ⇒ CsvFile

Returns a new instance of CsvFile.



13
14
15
16
# File 'lib/adapters/csv_file.rb', line 13

def initialize(file_path, columns = [0,1,2], debug = false)
  @files      = Dir.glob(file_path)
  @columns    = columns
end

Instance Method Details

#get_activitiesObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/adapters/csv_file.rb', line 22

def get_activities
  activities = []
  blank_time = Time.at(0.0)

  @files.each do |file|
    csv     = CSV::parse(File.open(file) { |f| f.read })
    headers = csv.shift

    csv.each_with_index do |row, i|
      activity    = row[@columns[0]]
      s           = row[@columns[1]]
      e           = row[@columns[2]]

      start_time  = parse_time(s)
      next if start_time == blank_time

      end_time    = parse_time(e)
      next if end_time == blank_time

      time_entry  = BBNW::Activity.new(activity, start_time, end_time)
      activities << time_entry
    end
  end
  activities
end

#log(message) ⇒ Object



18
19
20
# File 'lib/adapters/csv_file.rb', line 18

def log(message)
  puts message if @debug
end