motion-tickspot 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tick/timer.rb +33 -31
  3. data/lib/tick/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8bafc1996b9372f0d3212c08a153992c56032f19
4
- data.tar.gz: 6103752954c06dc8b0cf0752e26f909b536200a3
3
+ metadata.gz: bbe1e73c399461f4bc5ec3746e7435aa656c1230
4
+ data.tar.gz: f134be85e8d2e9d1d5cb852d4218c11a0f666b37
5
5
  SHA512:
6
- metadata.gz: 4bd371423e829956b082048988bd08bcf21e9bba591bf95d00d4c2575fd4acd1b8c311b0a3d2a7d402f7816868b2d1443e02d575bd3d824672983be23efae4b9
7
- data.tar.gz: dba7f186a682f583b05f0ff387bfa75d8233388a334ae718d71533fc8e196709551e50a0b646c0db89d20a49eb63dac71c92d0af39dc5740040f9e666f8ed8d9
6
+ metadata.gz: d1377ff6ef596214fb4eb2f56a9c7d6e2fb277ba1000086c87c0979b8ff036838202240e1e82da13a454c3f12a6cf001bae6e8ee4a9c546b35971198f1ecec40
7
+ data.tar.gz: 007a98e80155ff64b45e3c23daea353aa801be620fb5a1aa4bc435088050a3d4df92c69cc240e8dc0987d6c1a89d1fced0a94878f2af13a1d1cd27fdf68270d9
data/lib/tick/timer.rb CHANGED
@@ -1,135 +1,137 @@
1
1
  module Tick
2
-
2
+
3
3
  class Timer
4
4
  attr_accessor :start_time, :task, :time_spans
5
-
5
+
6
6
  def clear
7
7
  self.start_time = nil
8
8
  self.time_spans = []
9
9
  self.class.list.delete(self)
10
10
  true
11
11
  end
12
-
12
+
13
13
  def displayed_time
14
14
  hours = self.time_elapsed_in_hours.to_i
15
15
  minutes = (self.time_elapsed_in_seconds / 60).to_i - (hours * 60)
16
-
16
+
17
17
  hours = hours.to_s
18
18
  hours = "0#{hours}" if hours.length == 1
19
-
19
+
20
20
  minutes = minutes.to_s
21
21
  minutes = "0#{minutes}" if minutes.length == 1
22
-
22
+
23
23
  "#{hours}:#{minutes}"
24
24
  end
25
-
25
+
26
26
  def initialize
27
27
  self.start
28
28
  self
29
29
  end
30
-
30
+
31
31
  def is_paused
32
32
  self.start_time.nil?
33
33
  end
34
34
  alias_method :paused, :is_paused
35
+ alias_method :paused?, :is_paused
35
36
  alias_method :is_stopped, :is_paused
36
37
  alias_method :stopped, :is_paused
37
-
38
+
38
39
  def is_running
39
40
  !self.start_time.nil?
40
41
  end
41
42
  alias_method :running, :is_running
43
+ alias_method :running?, :is_running
42
44
  alias_method :is_started, :is_running
43
45
  alias_method :started, :is_running
44
-
46
+
45
47
  def start
46
48
  # Stop the current timer if it exists
47
49
  current_timer = self.class.current
48
50
  current_timer.stop if current_timer
49
-
51
+
50
52
  # Start the timer and add it to the
51
53
  # list of timers if it doesn't exist
52
54
  self.start_time = Time.now
53
55
  unless self.class.list.include?(self)
54
56
  self.class.list << self
55
57
  end
56
-
58
+
57
59
  true
58
60
  end
59
61
  alias_method :resume, :start
60
-
62
+
61
63
  def stop
62
64
  self.time_spans << Time.now - self.start_time
63
65
  self.start_time = nil
64
66
  true
65
67
  end
66
68
  alias_method :pause, :stop
67
-
69
+
68
70
  def submit!(options={}, &block)
69
71
  dateFormatter = NSDateFormatter.new
70
72
  dateFormatter.setDateFormat(DATE_FORMAT)
71
-
73
+
72
74
  params = {
73
75
  task_id: self.task.id,
74
76
  hours: self.time_elapsed_in_hours,
75
77
  date: Time.now
76
78
  }.merge!(options)
77
-
79
+
78
80
  entry = Entry.create(params) do |result|
79
81
  self.clear
80
82
  block.call(result) if block
81
83
  end
82
-
84
+
83
85
  self
84
86
  end
85
-
87
+
86
88
  def time_elapsed_in_seconds
87
89
  time_elapsed_in_seconds = 0
88
-
90
+
89
91
  # Add up time spans
90
92
  self.time_spans.each do |seconds|
91
93
  time_elapsed_in_seconds += seconds
92
94
  end
93
-
95
+
94
96
  # Add the current running time
95
97
  if self.start_time
96
98
  time_elapsed_in_seconds += Time.now - self.start_time
97
99
  end
98
-
100
+
99
101
  time_elapsed_in_seconds
100
102
  end
101
-
103
+
102
104
  def time_elapsed_in_hours
103
105
  self.time_elapsed_in_seconds / 60 / 60
104
106
  end
105
-
107
+
106
108
  def time_spans
107
109
  @time_spans ||= []
108
110
  end
109
-
111
+
110
112
  def self.current
111
113
  list.select{|timer|
112
114
  timer.is_running
113
115
  }.first
114
116
  end
115
-
117
+
116
118
  def self.list
117
119
  @@list ||= []
118
120
  end
119
-
121
+
120
122
  def self.start_with_task(task)
121
123
  timer = list.select{|timer|
122
124
  timer.task.id == task.id
123
125
  }.first
124
-
126
+
125
127
  if timer.nil?
126
128
  timer = new
127
129
  timer.task = task
128
130
  end
129
-
131
+
130
132
  timer
131
133
  end
132
-
134
+
133
135
  end
134
-
135
- end
136
+
137
+ end
data/lib/tick/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tick
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-tickspot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Pattison