Class: Harvestime::TimeFilter

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ TimeFilter

Returns a new instance of TimeFilter.



5
6
7
# File 'lib/harvestime/time_filter.rb', line 5

def initialize(client)
  @client = client
end

Instance Method Details

#all_timesObject

Current date only



14
15
16
# File 'lib/harvestime/time_filter.rb', line 14

def all_times
  @client.time.all
end

#all_times_in_date(time) ⇒ Object



17
18
19
# File 'lib/harvestime/time_filter.rb', line 17

def all_times_in_date(time)
  @client.time.all(time)
end

#build_entry(args = {}) ⇒ Object

Ensure client exists.



47
48
49
50
51
52
53
54
55
56
# File 'lib/harvestime/time_filter.rb', line 47

def build_entry(args = {})
 Harvest::TimeEntry.new(
 {     notes: '',
       hours: '0',
  project_id:  0,
     task_id:  0,
    spent_at:  Date.today.strftime('%a, %e %b %Y')
 }.merge(args)
 )
end

#build_entry_from_existing(entry) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/harvestime/time_filter.rb', line 57

def build_entry_from_existing(entry)
  Harvest::TimeEntry.new(
         notes: entry.notes,
         hours: entry.hours,
    project_id: entry.project_id,
       task_id: entry.task_id,
      spent_at: entry.spent_at
   )
end

#clear_daily_entriesObject



66
67
68
69
70
71
# File 'lib/harvestime/time_filter.rb', line 66

def clear_daily_entries
  @client.time.all.each do |entry|
    delete_entry(entry)
  end
  :success
end

#copy_date_range(other_account, start_date, end_date) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/harvestime/time_filter.rb', line 28

def copy_date_range(, start_date, end_date)
  date_range = (Date.parse(start_date.to_s)..Date.parse(end_date.to_s))
    .map { |day| day }      
  date_range.each do |date|
    .time.all(date).each do |entry|
      copy_entry_from(, entry)
    end
  end
end

#copy_entry_from(other_account, entry) ⇒ Object



25
26
27
# File 'lib/harvestime/time_filter.rb', line 25

def copy_entry_from(, entry)
  create_entry(build_entry_from_existing(entry))
end

#create_entry(entry) ⇒ Object



76
77
78
79
# File 'lib/harvestime/time_filter.rb', line 76

def create_entry (entry) 
  @client.time.create(entry)
  :success
end

#delete_date_range(start_date, end_date) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/harvestime/time_filter.rb', line 37

def delete_date_range(start_date, end_date)
  date_range = (Date.parse(start_date.to_s)..Date.parse(end_date.to_s))
    .map { |day| day }
  date_range.each do |date|
    all_times_in_date(date).each do |entry|
      delete_entry(entry)
    end
  end
end

#delete_entry(entry) ⇒ Object



72
73
74
75
# File 'lib/harvestime/time_filter.rb', line 72

def delete_entry(entry)
  @client.time.delete(entry)
  :success
end

#move_entry_from(other_account, entry) ⇒ Object



20
21
22
23
24
# File 'lib/harvestime/time_filter.rb', line 20

def move_entry_from(, entry)
  create_entry(build_entry_from_existing(entry))
  .time.delete(entry)
  :success
end

#scale_entry(time_entry, modifier) ⇒ Object



8
9
10
11
12
# File 'lib/harvestime/time_filter.rb', line 8

def scale_entry(time_entry, modifier)
  time_entry.hours = time_entry.hours * modifier
  @client.time.update(time_entry)
  time_entry.hours
end