hometime 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/hometime.rb +77 -0
  3. metadata +43 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0d979c13c4c4b2e786dcdb6a1b0c209c0c1999af32fc05fc166f9d1d6ba852bf
4
+ data.tar.gz: 4e93c58ac67218055fbb274ee306fab00966a7e190303e9ca5596b0f132b7d56
5
+ SHA512:
6
+ metadata.gz: 7450792ce32aa88f26d2c47202570fe23b50dbbc3194a046f791854da269b177be300e9ccbcfe378dba264dda238e4e245dc45f0e62ee1522ec4fc79277b9012
7
+ data.tar.gz: 7259f28495e8128b45050c75e76b508cc315b42005b8924279a22d4a4ba58becf1f7f23f4c0264b370517dea9f3a0fb6f20d5dc56c144d48ba49bc6023df9040
data/lib/hometime.rb ADDED
@@ -0,0 +1,77 @@
1
+ class Hometime
2
+ def self.initialize(duration)
3
+ puts 'What time did you start?'
4
+
5
+ @time = gets.chomp
6
+ @duration = duration
7
+
8
+ puts "Home time is #{leave_time.strftime('%H:%M')}."
9
+ puts "Only #{unit_formatted('hour', hours)}#{unit_formatted('minute', minutes)}" \
10
+ "#{unit_formatted('second', seconds)}until home time!"
11
+ christmas
12
+ end
13
+
14
+ private
15
+
16
+ # Time to leave
17
+ def self.leave_time
18
+ Time.new(
19
+ current_time.year,
20
+ current_time.month,
21
+ current_time.day,
22
+ hour, minute, 0
23
+ ) + @duration * 60 * 60
24
+ end
25
+
26
+ def self.current_time
27
+ Time.now
28
+ end
29
+
30
+ def self.hour
31
+ @time.partition(':').first
32
+ end
33
+
34
+ def self.minute
35
+ @time.partition(':').last
36
+ end
37
+
38
+ # Time remaining
39
+ def self.unit_formatted(unit, value)
40
+ case
41
+ when value == 1
42
+ "#{value} #{unit} "
43
+ when value > 1 && value < 60
44
+ "#{value} #{unit}s "
45
+ end
46
+ end
47
+
48
+ def self.seconds
49
+ (seconds_remaining % 60).floor
50
+ end
51
+
52
+ def self.minutes
53
+ ((seconds_remaining / 60) % 60).floor
54
+ end
55
+
56
+ def self.hours
57
+ (seconds_remaining / (60 * 60)).floor
58
+ end
59
+
60
+ def self.seconds_remaining
61
+ leave_time - current_time
62
+ end
63
+
64
+ # Days until Christmas
65
+ def self.christmas
66
+ puts "#{days_until_christmas_date} days until Christmas!" if days_until_christmas_date > 0
67
+ end
68
+
69
+ def self.christmas_date
70
+ this_year = Time.now.strftime('%Y').to_i
71
+ Time.new(this_year, 12, 25)
72
+ end
73
+
74
+ def self.days_until_christmas_date
75
+ ((((christmas_date - current_time) / 60) / 60) / 24).ceil
76
+ end
77
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hometime
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Hodgson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-08-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem to calculate when your shift ends
14
+ email: james.hodgson@sage.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/hometime.rb
20
+ homepage: https://rubygems.org/gems/hometime_jameshodgson
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 3.0.3
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Home Time
43
+ test_files: []