Module: Freshtrack
- Defined in:
- lib/freshtrack/version.rb,
lib/freshtrack.rb
Overview
:nodoc:
Defined Under Namespace
Modules: VERSION
Class Attribute Summary collapse
-
.config ⇒ Object
readonly
Returns the value of attribute config.
-
.project ⇒ Object
readonly
Returns the value of attribute project.
-
.task ⇒ Object
readonly
Returns the value of attribute task.
Class Method Summary collapse
- .company ⇒ Object
- .condense_time_data(time_data) ⇒ Object
- .create_entry(entry_data) ⇒ Object
- .get_data(project_name, options = {}) ⇒ Object
- .get_project_data(project_name) ⇒ Object
- .get_time_data(project_name, options = {}) ⇒ Object
- .group_date_data(date_data) ⇒ Object
- .init ⇒ Object
- .load_config ⇒ Object
- .project_task_mapping ⇒ Object
- .times_to_dates(time_data) ⇒ Object
- .token ⇒ Object
- .track(project_name, options = {}) ⇒ Object
Class Attribute Details
.config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/freshtrack.rb', line 9 def config @config end |
.project ⇒ Object (readonly)
Returns the value of attribute project.
9 10 11 |
# File 'lib/freshtrack.rb', line 9 def project @project end |
.task ⇒ Object (readonly)
Returns the value of attribute task.
9 10 11 |
# File 'lib/freshtrack.rb', line 9 def task @task end |
Class Method Details
.company ⇒ Object
20 21 22 |
# File 'lib/freshtrack.rb', line 20 def company config['company'] end |
.condense_time_data(time_data) ⇒ Object
46 47 48 49 |
# File 'lib/freshtrack.rb', line 46 def condense_time_data(time_data) date_data = times_to_dates(time_data) group_date_data(date_data) end |
.create_entry(entry_data) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/freshtrack.rb', line 85 def create_entry(entry_data) time_entry = FreshBooks::TimeEntry.new time_entry.project_id = project.project_id time_entry.task_id = task.task_id time_entry.date = entry_data['date'] time_entry.hours = entry_data['hours'] time_entry.notes = entry_data['notes'] result = time_entry.create if result true else STDERR.puts "warning: unsuccessful time entry creation for date #{entry_data['date']}" nil end end |
.get_data(project_name, options = {}) ⇒ Object
73 74 75 76 |
# File 'lib/freshtrack.rb', line 73 def get_data(project_name, = {}) get_project_data(project_name) get_time_data(project_name, ) end |
.get_project_data(project_name) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/freshtrack.rb', line 32 def get_project_data(project_name) raise unless mapping = project_task_mapping[project_name] @project = FreshBooks::Project.find_by_name(mapping[:project]) raise unless @project @task = FreshBooks::Task.find_by_name(mapping[:task]) raise unless @task end |
.get_time_data(project_name, options = {}) ⇒ Object
40 41 42 43 44 |
# File 'lib/freshtrack.rb', line 40 def get_time_data(project_name, = {}) Punch.load time_data = Punch.list(project_name, ) condense_time_data(time_data) end |
.group_date_data(date_data) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/freshtrack.rb', line 61 def group_date_data(date_data) separator = '-' * 20 grouped = date_data.group_by { |x| x['date'] } grouped.sort.inject([]) do |arr, (date, data)| this_date = { 'date' => date } this_date['hours'] = data.inject(0) { |sum, x| sum + x['hours'] } this_date['hours'] = ('%.2f' % this_date['hours']).to_f this_date['notes'] = data.collect { |x| x['log'].join("\n") }.join("\n" + separator + "\n") arr + [this_date] end end |
.init ⇒ Object
11 12 13 14 |
# File 'lib/freshtrack.rb', line 11 def init load_config FreshBooks.setup("#{company}.freshbooks.com", token) end |
.load_config ⇒ Object
16 17 18 |
# File 'lib/freshtrack.rb', line 16 def load_config @config = YAML.load(File.read(File.('~/.freshtrack.yml'))) end |
.project_task_mapping ⇒ Object
28 29 30 |
# File 'lib/freshtrack.rb', line 28 def project_task_mapping config['project_task_mapping'] end |
.times_to_dates(time_data) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/freshtrack.rb', line 51 def times_to_dates(time_data) time_data.each do |td| punch_in = td.delete('in') punch_out = td.delete('out') td['date'] = punch_in.to_date td['hours'] = (punch_out - punch_in).secs_to_hours end end |
.token ⇒ Object
24 25 26 |
# File 'lib/freshtrack.rb', line 24 def token config['token'] end |
.track(project_name, options = {}) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/freshtrack.rb', line 78 def track(project_name, = {}) data = get_data(project_name, ) data.each do |entry_data| create_entry(entry_data) end end |