Class: Toolshed::TimeTracking::Harvest
- Inherits:
-
Object
- Object
- Toolshed::TimeTracking::Harvest
- Extended by:
- Toolshed::TimeTracking
- Defined in:
- lib/toolshed/time_tracking/harvest.rb
Constant Summary collapse
- MAX_ATTEMPTS =
10
- GENERATED_HTML_FILE_LOCATION =
'/tmp/toolshed_generated_time_sheet.html'
Instance Attribute Summary collapse
-
#end_list_item ⇒ Object
Returns the value of attribute end_list_item.
-
#end_unorder_list ⇒ Object
Returns the value of attribute end_unorder_list.
-
#format ⇒ Object
Returns the value of attribute format.
-
#harvest_client ⇒ Object
Returns the value of attribute harvest_client.
-
#line_break ⇒ Object
Returns the value of attribute line_break.
-
#project_id ⇒ Object
Returns the value of attribute project_id.
-
#start_list_item ⇒ Object
Returns the value of attribute start_list_item.
-
#start_unorder_list ⇒ Object
Returns the value of attribute start_unorder_list.
Class Method Summary collapse
Instance Method Summary collapse
- #brought_to_you_by_message ⇒ Object
- #display ⇒ Object
- #formatter(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Harvest
constructor
A new instance of Harvest.
- #previous_notes(days_ago = 1, options = {}) ⇒ Object
- #previous_time_entries(days_ago, options = {}) ⇒ Object
- #todays_notes ⇒ Object
- #todays_time_entries ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Harvest
Returns a new instance of Harvest.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/toolshed/time_tracking/harvest.rb', line 13 def initialize(={}) username = Toolshed::Client.instance.time_tracking_username password = Toolshed::Client.instance.time_tracking_password owner = Toolshed::Client.instance.time_tracking_owner username = [:username] unless [:username].nil? password = [:password] unless [:password].nil? owner = [:sub_domain] unless [:sub_domain].nil? self.harvest_client = ::Harvest.client(subdomain: owner, username: username, password: password) self.project_id = [:project_id] unless !.has_key?(:project_id) # setup formatting formatter() end |
Instance Attribute Details
#end_list_item ⇒ Object
Returns the value of attribute end_list_item.
11 12 13 |
# File 'lib/toolshed/time_tracking/harvest.rb', line 11 def end_list_item @end_list_item end |
#end_unorder_list ⇒ Object
Returns the value of attribute end_unorder_list.
11 12 13 |
# File 'lib/toolshed/time_tracking/harvest.rb', line 11 def end_unorder_list @end_unorder_list end |
#format ⇒ Object
Returns the value of attribute format.
11 12 13 |
# File 'lib/toolshed/time_tracking/harvest.rb', line 11 def format @format end |
#harvest_client ⇒ Object
Returns the value of attribute harvest_client.
11 12 13 |
# File 'lib/toolshed/time_tracking/harvest.rb', line 11 def harvest_client @harvest_client end |
#line_break ⇒ Object
Returns the value of attribute line_break.
11 12 13 |
# File 'lib/toolshed/time_tracking/harvest.rb', line 11 def line_break @line_break end |
#project_id ⇒ Object
Returns the value of attribute project_id.
11 12 13 |
# File 'lib/toolshed/time_tracking/harvest.rb', line 11 def project_id @project_id end |
#start_list_item ⇒ Object
Returns the value of attribute start_list_item.
11 12 13 |
# File 'lib/toolshed/time_tracking/harvest.rb', line 11 def start_list_item @start_list_item end |
#start_unorder_list ⇒ Object
Returns the value of attribute start_unorder_list.
11 12 13 |
# File 'lib/toolshed/time_tracking/harvest.rb', line 11 def start_unorder_list @start_unorder_list end |
Class Method Details
.create_instance(options = {}) ⇒ Object
115 116 117 |
# File 'lib/toolshed/time_tracking/harvest.rb', line 115 def self.create_instance(={}) Toolshed::TimeTracking::Harvest.new() end |
Instance Method Details
#brought_to_you_by_message ⇒ Object
74 75 76 |
# File 'lib/toolshed/time_tracking/harvest.rb', line 74 def "#{self.line_break}Provided by Toolshed https://rubygems.org/gems/toolshed#{self.line_break}" end |
#display ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/toolshed/time_tracking/harvest.rb', line 96 def display notes = self.previous_notes notes = "#{notes}#{self.line_break}#{self.line_break}#{self.todays_notes}" notes = "#{notes}#{self.}" if (self.format == 'html') FileUtils.rm_rf(Toolshed::TimeTracking::Harvest::GENERATED_HTML_FILE_LOCATION) File.open(Toolshed::TimeTracking::Harvest::GENERATED_HTML_FILE_LOCATION, 'w') {|f| f.write(notes) } Launchy.open( Toolshed::TimeTracking::Harvest::GENERATED_HTML_FILE_LOCATION ) do |exception| puts "Attempted to open #{uri} and failed because #{exception}" end puts "Checkout out your default or open browser!" else puts notes end return end |
#formatter(options = {}) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/toolshed/time_tracking/harvest.rb', line 78 def formatter(={}) if ([:format] && [:format] == 'html') self.format = 'html' self.line_break = "<br>" self.start_list_item = "<li>" self.end_list_item = "</li>" self.start_unorder_list = "<ul>" self.end_unorder_list = "</ul>" else self.format = 'text' self.line_break = "\n" self.start_list_item = "" self.end_list_item = "" self.start_unorder_list = "" self.end_unorder_list = "" end end |
#previous_notes(days_ago = 1, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/toolshed/time_tracking/harvest.rb', line 39 def previous_notes(days_ago=1, ={}) notes = "Previous:#{self.line_break}" time_entries = previous_time_entries(days_ago, ) notes = "#{notes}#{self.start_unorder_list}" time_entries.each do |time_entry| notes = "#{notes}#{self.start_list_item}#{time_entry.notes}#{self.end_list_item}" if (self.end_list_item == '') notes = "#{notes}#{self.line_break}" end end notes = "#{notes}#{self.end_unorder_list}" notes end |
#previous_time_entries(days_ago, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/toolshed/time_tracking/harvest.rb', line 29 def previous_time_entries(days_ago, ={}) entries = self.harvest_client.time.all((DateTime.now - days_ago), self.project_id) if (entries.size > 0 || days_ago == Toolshed::TimeTracking::Harvest::MAX_ATTEMPTS) entries else entries = self.previous_time_entries(days_ago + 1) end end |
#todays_notes ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/toolshed/time_tracking/harvest.rb', line 60 def todays_notes notes = "Today:#{self.line_break}" notes = "#{notes}#{self.start_unorder_list}" self.todays_time_entries.each do |time_entry| notes = "#{notes}#{self.start_list_item}#{time_entry.notes}#{self.end_list_item}" if (self.end_list_item == '') notes = "#{notes}#{self.line_break}" end end notes = "#{notes}#{self.end_unorder_list}" notes end |
#todays_time_entries ⇒ Object
56 57 58 |
# File 'lib/toolshed/time_tracking/harvest.rb', line 56 def todays_time_entries self.harvest_client.time.all(Time.now, self.project_id) end |