fourtwenty 0.1.0

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 (6) hide show
  1. checksums.yaml +7 -0
  2. data/bin/420 +4 -0
  3. data/bin/fourtwenty +4 -0
  4. data/lib/420.rb +78 -0
  5. data/lib/local/en.yml +10 -0
  6. metadata +49 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 93ea864b763ab81c5f11be9c6b189464c1f6c8f3
4
+ data.tar.gz: da40f16a7e0ce66fa73a5d983500dff723ebbabe
5
+ SHA512:
6
+ metadata.gz: 4875344433402bf58e7d6448e566a74836239929255f5cbcda66bc47c8574f865d9ec60d54803b5e3ec09f0b27f06b897eee21103b0f746e9de337d76724275c
7
+ data.tar.gz: 8d1fdf3b5b48c732b900aef81d31fafcf73ca1bc1ed825282698b57076491b6b7e27b592038769d38bc4041f9399bdebdd6dcd971fa3c8017fea73d1a8aface0
data/bin/420 ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require '420'
4
+ FourTwenty.run
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require '420'
4
+ FourTwenty.run
@@ -0,0 +1,78 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require "thor"
5
+ require "time_diff"
6
+ require 'i18n'
7
+
8
+
9
+ class App < Thor
10
+ desc "time", "Gets the time left until the next 4:20"
11
+ def time(time=Time.new)
12
+ if time.is_a? String
13
+ time = Time.parse(time)
14
+ end
15
+ return FourTwenty.timeUntil420(time)
16
+ end
17
+ default_task :time
18
+ end
19
+
20
+
21
+ # FourTwenty is the includable ruby module to run the thor app and test
22
+ module FourTwenty
23
+ # Check if it is 420
24
+ def self.is420(time=Time.new)
25
+ if time.strftime("%I:%M") == "04:20"
26
+ return true
27
+ end
28
+ return false
29
+ end
30
+
31
+ def self.getNextBowlTime(time=Time.new)
32
+ bowl_times = [Time.local(time.year, time.month, time.day, 4, 20),
33
+ Time.local(time.year, time.month, time.day, 16, 20)]
34
+ if time < bowl_times[0]
35
+ return bowl_times[0]
36
+ elsif time > bowl_times[0] and time < bowl_times[1]
37
+ return bowl_times[1]
38
+ end
39
+ end
40
+
41
+ # Get the time until 420
42
+ def self.timeUntil420(time=Time.new)
43
+ # This truncates the seconds off the time, to prevent rounding
44
+ time = Time.parse(time.strftime("%H:%M:00"), time)
45
+ time = Time.local(time.year, time.month, time.day, time.strftime("%I"), time.strftime("%M"))
46
+
47
+ # This means it's exactly 420!
48
+ if is420(time)
49
+ local = I18n.t :happy, :scope => 'returns'
50
+ return local
51
+ end
52
+
53
+ time_until = Time.diff(time, getNextBowlTime(time))
54
+
55
+ # It's minutes until 420
56
+ if time_until[:hour] == 0
57
+ local = I18n.t :time_minutes, :scope => 'returns'
58
+ return local % [time_until[:minute]]
59
+ # It's hours until 420
60
+ else
61
+ local = I18n.t :time, :scope => 'returns'
62
+ return local % [time_until[:hour], time_until[:minute]]
63
+ end
64
+ end
65
+
66
+ def self.run
67
+ dir = File.dirname(__FILE__)
68
+ I18n.load_path = Dir[dir + '/local/*.yml', dir + '/local/*.rb']
69
+ I18n.enforce_available_locales = false
70
+ puts App.start
71
+ end
72
+ def self.run_from_time(args)
73
+ dir = File.dirname(__FILE__)
74
+ I18n.load_path = Dir[dir + '/local/*.yml', dir + '/local/*.rb']
75
+ I18n.enforce_available_locales = false
76
+ App.start(args)
77
+ end
78
+ end
@@ -0,0 +1,10 @@
1
+ ---
2
+ en:
3
+ returns:
4
+ hour: hour
5
+ hours: hours
6
+ minute: minute
7
+ minutes: minutes
8
+ time: "%s hours and %s minutes until 4:20!"
9
+ time_minutes: "%s minutes until 4:20!"
10
+ happy: "Happy 4:20!"
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fourtwenty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mediachicken
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple command to display the amount of time left until 420
14
+ email: self@mediachicken.com
15
+ executables:
16
+ - '420'
17
+ - fourtwenty
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/420
22
+ - bin/fourtwenty
23
+ - lib/420.rb
24
+ - lib/local/en.yml
25
+ homepage: http://github.com/mediachicken/420
26
+ licenses:
27
+ - BSD
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.4.2
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Countdown to 420
49
+ test_files: []