hour 0.3.0 → 0.5.1

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 +7 -1
  3. data/lib/hour/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 553698ff721afd84b24cc90c5c829e309227259c
4
- data.tar.gz: e655e4ddf2e4f79e627fab5b392b13b1f43fe27d
3
+ metadata.gz: b7d9267b3b089937946d971b89f0af4d5562a5ec
4
+ data.tar.gz: 00d4d94e7769afcb2e127e9d539ccd19decd8bed
5
5
  SHA512:
6
- metadata.gz: 41ce340d977fdcd7a28ef10c633e63cdb9bfa285081e501e0c06bb279a9e55736040e5368333c2d80d936e0a7a2c7bdf1cf3d015d131130c40c4644a2658e084
7
- data.tar.gz: 023e742e832fd8ed7c1fc4c09ee7fe6dff3abc0ef59770151dd2c76ce72b150f942778b17d28f3d53ceea4e82d3ce2031281e596c6efc0a6fbb65e75b741b7d7
6
+ metadata.gz: 98389becbcd5fc96e451d38907e18c5b29c99a235e76593d8ea39e7ddc07351f6917ff06f779f1a08402febeef3d0222290fda8c4a5e6913c1f57ccc8acf7cb9
7
+ data.tar.gz: 668b7b56bdc3dbc1802c2d29213f729ffa44f5c67ea6217a39b148c51a371f59d48f7a1b0eab52c01dce7059aa7dd03e1d4774c460cc3803d728c2a2ca17e899
@@ -2,13 +2,14 @@
2
2
 
3
3
  module Hour
4
4
  class Hour
5
- attr_reader :hours, :minutes, :to_seconds, :days, :hours_less_days, :to_s, :to_formatted_s, :to_a, :to_time, :minutes_in_base10
5
+ attr_reader :hours, :minutes, :to_seconds, :days, :hours_less_days, :to_s, :to_formatted_s, :to_a, :to_time, :minutes_in_base10, :to_base10
6
6
 
7
7
  def initialize(hours, minutes = 0)
8
8
  hours, minutes = hours.split(':') if hours.is_a? String
9
9
  @minutes = [0, minutes.to_i, 59].sort[1] # Constrains assignment to the middle value, w/o the #Clamp method
10
10
  @minutes_in_base10 = @minutes.to_f / 60
11
11
  @to_a = [@hours = hours.to_i, @minutes]
12
+ @to_base10 = @hours + @minutes_in_base10
12
13
  @to_s = "#{'%02d' % @hours}:#{'%02d' % @minutes}" # Formats single-digits such that '1' will be '01'
13
14
  @to_seconds = (@hours * 60 + @minutes) * 60
14
15
  @days = @hours / 24 || 0
@@ -38,6 +39,11 @@ module Hour
38
39
  self.new(hour || time_obj.hour, time_obj.min)
39
40
  end
40
41
 
42
+ def self.from_base10(num)
43
+ hour, minute = num.divmod(1)
44
+ self.new(hour, minute * 60)
45
+ end
46
+
41
47
  alias_method :to_days, :days # DEPRECATION: to_days
42
48
  alias_method :to_hours_less_days, :hours_less_days # DEPRECATION: to_hours_less_days
43
49
 
@@ -1,3 +1,3 @@
1
1
  module Hour
2
- VERSION = "0.3.0"
2
+ VERSION = "0.5.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - davegregg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-17 00:00:00.000000000 Z
11
+ date: 2017-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler