refined-refinements 0.0.1.1 → 0.0.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: 9e237cd63850813d78118fb36f6d6a2af9997aad27efd52a29558364392a4320
4
- data.tar.gz: acb9d42dd6b27cd7ff457c1dc496e4bf315e86a01ecac2f8fc6e6d2f41e5d0c9
3
+ metadata.gz: d0fd4d163da31398779d6f4afe521390e7c62f6a3b34e1fe1b3bc196c5ee7cbf
4
+ data.tar.gz: d043059bd3150ad6f7955f9e6fa5b36a24132b6dc9e16e597dc731a7e9b9b320
5
5
  SHA512:
6
- metadata.gz: afc0245977ea79e641818fb28b1415e6876a7da70ca673c46b982c35a3d8946ff3472ac508594966845bf51f87503f643c81616ac8216b891717b8b679e9ad33
7
- data.tar.gz: bd488952fb4efe31047de84b29c6f222e23b2a36f39c4735802ce77b8b424216f726741eec2fbd04e07c7bc6a0940b693fb57c82b5badeca11cf8167c69b2beb
6
+ metadata.gz: 1e58cc2b74ceeacb4d1489a0f13be7ea760e9a846b219c3a8578fc892a7470856fc04b86701b8039bc0e515f2c88734ceada24b2f93420032d0e0c975138013b
7
+ data.tar.gz: dbc9957e8e8c8eecf29eb8c9341335f1a9086f537e707005fb4f1cfd908acc5b52971b85f3269d33713b9f8b1a293f9abc13b62cd6eb7aaff906a447e72cde10
@@ -0,0 +1,70 @@
1
+ class Hour
2
+ def self.parse(string)
3
+ hours, minutes = string.split(':')
4
+ self.new(hours.to_i, minutes.to_i)
5
+ end
6
+
7
+ def self.now
8
+ now = Time.now
9
+ self.new(now.hour, now.min)
10
+ end
11
+
12
+ attr_reader :minutes
13
+ def initialize(hours, minutes = 0)
14
+ @minutes = (hours * 60) + minutes
15
+ end
16
+
17
+ # Doesn't work if it's smaller - larger:
18
+ # Hour.parse('0:58') - Hour.parse('1:00')
19
+ # => -1:58
20
+ [:+, :-].each do |method_name|
21
+ define_method(method_name) do |hour_or_minutes|
22
+ if hour_or_minutes.is_a?(self.class)
23
+ self.class.new(0, @minutes.send(method_name, hour_or_minutes.minutes))
24
+ elsif hour_or_minutes.is_a?(Integer)
25
+ self.class.new(0, @minutes.send(method_name, hour_or_minutes))
26
+ else
27
+ raise TypeError.new("Hour or Integer (for minutes) expected, got #{hour_or_minutes.class}.")
28
+ end
29
+ end
30
+ end
31
+
32
+ def hours
33
+ if (@minutes / 60).round > (@minutes / 60)
34
+ (@minutes / 60).round - 1
35
+ else
36
+ (@minutes / 60).round
37
+ end
38
+ end
39
+
40
+ # Currently unused, but it might be in the future.
41
+ # def *(rate)
42
+ # (@minutes * (rate / 60.0)).round(2)
43
+ # end
44
+
45
+ [:==, :eql?, :<, :<=, :>, :>=, :<=>].each do |method_name|
46
+ define_method(method_name) do |anotherHour|
47
+ if anotherHour.is_a?(self.class)
48
+ self.minutes.send(method_name, anotherHour.minutes)
49
+ elsif anotherHour.is_a?(Time)
50
+ self.send(method_name, Hour.now)
51
+ else
52
+ raise TypeError.new("#{self.class}##{method_name} expects #{self.class} or Time object.")
53
+ end
54
+ end
55
+ end
56
+
57
+ def inspect
58
+ "#{self.hours}:#{format('%02d', self.minutes_over_the_hour)}"
59
+ end
60
+ alias_method :to_s, :inspect
61
+
62
+ def to_time(today = Time.now)
63
+ Time.new(today.year, today.month, today.day, self.hours, self.minutes_over_the_hour)
64
+ end
65
+
66
+ protected
67
+ def minutes_over_the_hour
68
+ @minutes - (self.hours * 60)
69
+ end
70
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refined-refinements
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James C Russell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-20 00:00:00.000000000 Z
11
+ date: 2017-12-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: "."
14
14
  email: james@101ideas.cz
@@ -26,6 +26,7 @@ files:
26
26
  - lib/refined-refinements/curses/colours.rb
27
27
  - lib/refined-refinements/curses/commander.rb
28
28
  - lib/refined-refinements/date.rb
29
+ - lib/refined-refinements/hour.rb
29
30
  - lib/refined-refinements/matching.rb
30
31
  - lib/refined-refinements/string.rb
31
32
  homepage: http://github.com/botanicus/refined-refinements