Class: Rescuetime::Application
- Inherits:
-
Object
- Object
- Rescuetime::Application
- Includes:
- Debug
- Defined in:
- lib/rescuetime/application.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#finished_at ⇒ Object
readonly
Returns: Time of where app where detected to not be active anymore, or Time now if not finished yet.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
-
.create(options = {}) ⇒ Object
TODO.
- .current_application_name ⇒ Object
- .current_window_title ⇒ Object
-
.to_yaml(apps = []) ⇒ Object
NEW && UNTESTED.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Returns: boolean, if application is still active window.
-
#active_time ⇒ Object
Returns difference between StartTime and now if still active, or StartTime and FinishedTime if not ative anymore.
- #extended_info ⇒ Object
- #finished? ⇒ Boolean
-
#initialize(options = {}) ⇒ Application
constructor
Constructor: Call with => true to get debug messages.
- #os_username ⇒ Object
- #to_s ⇒ Object
-
#to_upload_data ⇒ Object
TODO.
- #to_yaml ⇒ Object
Methods included from Debug
Constructor Details
#initialize(options = {}) ⇒ Application
Constructor: Call with => true to get debug messages
49 50 51 52 53 54 55 56 57 |
# File 'lib/rescuetime/application.rb', line 49 def initialize( = {}) @debug = [:debug] @name = [:name] || current_application_name @title = [:title] || current_window_title @created_at = Time.now @finished_at = nil @active = true end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
36 37 38 |
# File 'lib/rescuetime/application.rb', line 36 def created_at @created_at end |
#finished_at ⇒ Object (readonly)
Returns: Time of where app where detected to not be active anymore, or Time now if not finished yet
69 70 71 |
# File 'lib/rescuetime/application.rb', line 69 def finished_at @finished_at end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
36 37 38 |
# File 'lib/rescuetime/application.rb', line 36 def name @name end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
36 37 38 |
# File 'lib/rescuetime/application.rb', line 36 def title @title end |
Class Method Details
.create(options = {}) ⇒ Object
TODO
40 41 42 43 44 |
# File 'lib/rescuetime/application.rb', line 40 def self.create( = {}) name = [:name] || self.current_application_name klass = Rescuetime::Extension.get(name) || self klass.new() end |
.current_application_name ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rescuetime/application.rb', line 13 def self.current_application_name cmd = <<-CMD xprop -id `xprop -root | awk '/_NET_ACTIVE_WINDOW/ {print $5; exit;}'` | awk -F = '/WM_CLASS/ {print $2; exit;}'| awk '{print $2}' | sed 's/^"//g' | sed 's/"$//g' CMD `#{cmd}`.strip end |
.current_window_title ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rescuetime/application.rb', line 25 def self.current_window_title cmd = <<-CMD xprop -id `xprop -root | awk '/_NET_ACTIVE_WINDOW/ {print $5; exit;}'` | awk -F = '/^WM_NAME/ {print $2; exit;}' | sed -e's/^ *"//g' | sed -e's/\\"$//g' CMD `#{cmd}`.strip end |
.to_yaml(apps = []) ⇒ Object
NEW && UNTESTED
6 7 8 9 10 11 |
# File 'lib/rescuetime/application.rb', line 6 def self.to_yaml(apps = []) yaml = "---\n" [*apps].each { |app| yaml += app.to_yaml } return yaml end |
Instance Method Details
#active? ⇒ Boolean
Returns: boolean, if application is still active window
78 79 80 81 82 83 84 85 86 |
# File 'lib/rescuetime/application.rb', line 78 def active? return @active unless @active @active = @name == current_application_name && @title == current_window_title finish! unless @active return @active end |
#active_time ⇒ Object
Returns difference between StartTime and now if still active, or StartTime and FinishedTime if not ative anymore
94 95 96 |
# File 'lib/rescuetime/application.rb', line 94 def active_time (active?) ? (Time.now - @created_at) : (@finished_at - @created_at) end |
#extended_info ⇒ Object
102 103 104 |
# File 'lib/rescuetime/application.rb', line 102 def extended_info (@extended_info || "").gsub("\000", "").gsub("'", "`") end |
#finished? ⇒ Boolean
88 89 90 |
# File 'lib/rescuetime/application.rb', line 88 def finished? !active? end |
#os_username ⇒ Object
106 107 108 |
# File 'lib/rescuetime/application.rb', line 106 def os_username @os_username ||= `uname -n`.strip + "\\" + `id -un`.strip end |
#to_s ⇒ Object
98 99 100 |
# File 'lib/rescuetime/application.rb', line 98 def to_s "#{name}:#{title}:#{extended_info}" end |
#to_upload_data ⇒ Object
TODO
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/rescuetime/application.rb', line 111 def to_upload_data return "" if name.empty? out = "- os_username: '#{os_username}'\n" out += " app_name: '#{name}'\n" out += " window_title: '#{title}'\n" out += " extended_info: '#{extended_info}'\n" out += " start_time: #{created_at}\n" out += " end_time: #{finished_at}\n" return out end |
#to_yaml ⇒ Object
124 125 126 |
# File 'lib/rescuetime/application.rb', line 124 def to_yaml to_upload_data end |