hour 0.1.1 → 0.1.2

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/hour.rb +28 -26
  3. data/lib/hour/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a0802d7c486e0e4a00c8c033ec186ef4eb88c9a
4
- data.tar.gz: 531f83fac6fcad87e331b08c4d1c494aef855dad
3
+ metadata.gz: 250f76a57521fe36bc213b0bd6cf7d742c7ecdb4
4
+ data.tar.gz: 203bf89298d3827e8197b4d51afbdf48f412f8ec
5
5
  SHA512:
6
- metadata.gz: 869f5426e02999aa0acdcf1eb43bfafb4f259c3c9d5b396cd8a6715a46d267453f47f6fbbcce2019e2b03ce54b7cd681926678b50bac00b04c20b3a1f3f40b10
7
- data.tar.gz: 8c11398257ca0a5023d7b6ac7330abf42fddc2c5432dc0254bc3e2ed6f57e3d2fe764dc67fd6d1a55199045e65d753bf5f0b851f4a3ee0933e4a66a167926655
6
+ metadata.gz: f00705691b427d5f6f6ebe1ea74296a2c8b850b1db85854eaefdd4f9c5913efd6f6ac15c0785aefae202937cdfd8d566edd2356e2d08133bc9207cc0f3784e70
7
+ data.tar.gz: 6400d36b10f6e8afb0560017c695d9a28d75806ee05ba1a8f9117ae09b73e61e7990e99929ffd64bf9a456f274dd3caab181da69cf68ccc6bcd707245178e7b6
data/lib/hour.rb CHANGED
@@ -1,32 +1,34 @@
1
1
  require "hour/version"
2
2
 
3
- class Hour
4
- attr_reader :hours, :minutes, :to_seconds, :to_days, :to_hours_less_days, :to_s, :to_formatted_s, :to_a, :to_time
3
+ module Hour
4
+ class Hour
5
+ attr_reader :hours, :minutes, :to_seconds, :to_days, :to_hours_less_days, :to_s, :to_formatted_s, :to_a, :to_time
5
6
 
6
- def initialize(hours, minutes = 0)
7
- hours, minutes = hours.split(':').map(&:to_i) if hours.is_a? String
8
- minutes = [1, minutes, 59].sort[1] #clamp: constrains the assignment to the middle value
9
- @to_s = "#{'%02d' % hours}:#{'%02d' % minutes}"
10
- @to_a = [@hours = hours, @minutes = minutes]
11
- @to_seconds = ((hours * 60) + minutes) * 60
12
- @to_days = hours / 24
13
- @to_hours_less_days = hours - 24 * @to_days
14
- @to_formatted_s = "#{@to_days} day#{'s' unless @to_days == 1}, " +
15
- "#{@to_hours_less_days} hour#{'s' unless @to_hours_less_days == 1}, " +
16
- "#{minutes} minute#{'s' unless minutes == 1}"
17
- @to_time = Time.new(
18
- 0, #year
19
- 1, #month
20
- 1 + @to_days, #day
21
- @to_hours_less_days, #hour
22
- minutes, #minute
23
- 0, #second
24
- 0 #UTC #TODO: gracefully handle both the new Time.zone format and the deprecated UTC
25
- )
26
- end
7
+ def initialize(hours, minutes = 0)
8
+ hours, minutes = hours.split(':').map(&:to_i) if hours.is_a? String
9
+ minutes = [1, minutes, 59].sort[1] #clamp: constrains the assignment to the middle value
10
+ @to_s = "#{'%02d' % hours}:#{'%02d' % minutes}"
11
+ @to_a = [@hours = hours, @minutes = minutes]
12
+ @to_seconds = ((hours * 60) + minutes) * 60
13
+ @to_days = hours / 24
14
+ @to_hours_less_days = hours - 24 * @to_days
15
+ @to_formatted_s = "#{@to_days} day#{'s' unless @to_days == 1}, " +
16
+ "#{@to_hours_less_days} hour#{'s' unless @to_hours_less_days == 1}, " +
17
+ "#{minutes} minute#{'s' unless minutes == 1}"
18
+ @to_time = Time.new(
19
+ 0, #year
20
+ 1, #month
21
+ 1 + @to_days, #day
22
+ @to_hours_less_days, #hour
23
+ minutes, #minute
24
+ 0, #second
25
+ 0 #UTC #TODO: gracefully handle both the new Time.zone format and the deprecated UTC
26
+ )
27
+ end
27
28
 
28
- def self.from_time(time_obj)
29
- Hour.new(time_obj.hour, time_obj.min)
30
- end
29
+ def self.from_time(time_obj)
30
+ Hour.new(time_obj.hour, time_obj.min)
31
+ end
31
32
 
33
+ end
32
34
  end
data/lib/hour/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hour
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - davegregg