time-duration 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0442605737d2771dfc2851b423314004a3ff36c90ca333d3a853b65406383312
4
- data.tar.gz: aa2393be39bea4695c7a58c0d36b336b622484faa592f077af1cd0e5b97ee5f1
3
+ metadata.gz: 352c7207321f8fdb32924ec6eaff8b4e75e77d7d1bf14378fc8ec035cbe59829
4
+ data.tar.gz: 015b1a1b49f3a12d90df40ffcade70c557038afd1ea73d20916b2cd2a66b35ce
5
5
  SHA512:
6
- metadata.gz: 3a62509caf01a6cf2ed7ef996d3b3bbb19038cfd2da849e7657aa788251def6fd3db46b8faa8e769482b75305f7f85a51787fa244c73981f2b9c8086117151ef
7
- data.tar.gz: b151a4f20375f6067bec4dea7265db305d9a198d3c9a8d09a0568a8a398f1dca80b4a49ac02c5cf416f1f35225bb40035b6242b4887eea870195229f56aa5429
6
+ metadata.gz: 480146a36635db00d21432e380cee4c76a84979531d718f6585c07efcebcbeb1ffbfaddf110ac1cad46e4f243793a1fcd42c6c2a6df7c86522343f860465a6b1
7
+ data.tar.gz: fd059a60b892f96f0e27fd2b10e1d07bb2d5aef7ed665214db376a0c86dfe8028c69533f9ae5779d1feba753b4328c253effcc1ccfddfda1dcf204e0f68c13c0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- time-duration (0.1.1)
4
+ time-duration (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -34,9 +34,9 @@ duration.to_s # => "2:10"
34
34
 
35
35
  ```ruby
36
36
  TimeDuration::Duration.new # => 0:00
37
- TimeDuration::Duration.new(minutes: 10) # => 0:10
38
- TimeDuration::Duration.new(hours: 1) # => 1:00
39
- TimeDuration::Duration.new(hours: 1, minutes: 10) # => 1:10
37
+ TimeDuration::Duration.new(minute: 10) # => 0:10
38
+ TimeDuration::Duration.new(hour: 1) # => 1:00
39
+ TimeDuration::Duration.new(hour: 1, minute: 10) # => 1:10
40
40
  ```
41
41
 
42
42
  ### Operations
@@ -1,4 +1,4 @@
1
- require "time_duration/version"
1
+ require 'time_duration/version'
2
2
 
3
3
  module TimeDuration
4
4
  def self.parse(args)
@@ -8,44 +8,44 @@ module TimeDuration
8
8
  class Duration
9
9
  include Comparable
10
10
 
11
- attr_accessor :seconds
11
+ attr_accessor :second
12
12
 
13
13
  # TODO: format指定できるようにする
14
- def self.parse(time_as_string)
15
- hours, minutes = time_as_string.split(':').map(&:to_i)
16
- new(hours: hours, minutes: minutes)
14
+ def self.parse(time_as_string, format: '%H:%M')
15
+ hour, minute = time_as_string.split(':').map(&:to_i)
16
+ new(hour: hour, minute: minute)
17
17
  end
18
18
 
19
- def initialize(hours: 0, minutes: 0, seconds: 0)
20
- hours = hours.to_i
21
- minutes = minutes.to_i
22
- seconds = seconds.to_i
23
- @seconds = hours * 3600 + minutes * 60 + seconds
19
+ def initialize(hour: 0, minute: 0, second: 0)
20
+ hour = hour.to_i
21
+ minute = minute.to_i
22
+ second = second.to_i
23
+ @second = hour * 3600 + minute * 60 + second
24
24
  end
25
25
 
26
- def hours
27
- minutes / 60 + seconds / 3600
26
+ def hour
27
+ minute / 60 + second / 3600
28
28
  end
29
29
 
30
- def minutes
31
- (seconds / 60) % 60
30
+ def minute
31
+ (second / 60) % 60
32
32
  end
33
33
 
34
34
  # TODO: format指定できるようにする
35
35
  def to_s
36
- "%d:%02d" % [hours, minutes]
36
+ "%d:%02d" % [hour, minute]
37
37
  end
38
38
 
39
39
  def +(time_duration)
40
- self.class.new(seconds: seconds + time_duration.seconds)
40
+ self.class.new(second: second + time_duration.second)
41
41
  end
42
42
 
43
43
  def -(time_duration)
44
- self.class.new(seconds: seconds - time_duration.seconds)
44
+ self.class.new(second: second - time_duration.second)
45
45
  end
46
46
 
47
47
  def <=>(time_duration)
48
- self.seconds <=> time_duration.seconds
48
+ self.second <=> time_duration.second
49
49
  end
50
50
 
51
51
  # override
@@ -1,3 +1,3 @@
1
1
  module TimeDuration
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: time-duration
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
  - Daiki Matoba