Module: FourTwenty
- Defined in:
- lib/420.rb
Overview
FourTwenty is the includable ruby module to run the thor app and test
Class Method Summary collapse
- .getNextBowlTime(time = Time.new) ⇒ Object
-
.is420(time = Time.new) ⇒ Object
Check if it is 420.
- .run ⇒ Object
- .run_from_time(args) ⇒ Object
-
.timeUntil420(time = Time.new) ⇒ Object
Get the time until 420.
Class Method Details
.getNextBowlTime(time = Time.new) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/420.rb', line 31 def self.getNextBowlTime(time=Time.new) bowl_times = [Time.local(time.year, time.month, time.day, 4, 20), Time.local(time.year, time.month, time.day, 16, 20)] if time < bowl_times[0] return bowl_times[0] elsif time > bowl_times[0] and time < bowl_times[1] return bowl_times[1] end end |
.is420(time = Time.new) ⇒ Object
Check if it is 420
24 25 26 27 28 29 |
# File 'lib/420.rb', line 24 def self.is420(time=Time.new) if time.strftime("%I:%M") == "04:20" return true end return false end |
.run ⇒ Object
66 67 68 69 70 71 |
# File 'lib/420.rb', line 66 def self.run dir = File.dirname(__FILE__) I18n.load_path = Dir[dir + '/local/*.yml', dir + '/local/*.rb'] I18n.enforce_available_locales = false puts App.start end |
.run_from_time(args) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/420.rb', line 72 def self.run_from_time(args) dir = File.dirname(__FILE__) I18n.load_path = Dir[dir + '/local/*.yml', dir + '/local/*.rb'] I18n.enforce_available_locales = false App.start(args) end |
.timeUntil420(time = Time.new) ⇒ Object
Get the time until 420
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/420.rb', line 42 def self.timeUntil420(time=Time.new) # This truncates the seconds off the time, to prevent rounding time = Time.parse(time.strftime("%H:%M:00"), time) time = Time.local(time.year, time.month, time.day, time.strftime("%I"), time.strftime("%M")) # This means it's exactly 420! if is420(time) local = I18n.t :happy, :scope => 'returns' return local end time_until = Time.diff(time, getNextBowlTime(time)) # It's minutes until 420 if time_until[:hour] == 0 local = I18n.t :time_minutes, :scope => 'returns' return local % [time_until[:minute]] # It's hours until 420 else local = I18n.t :time, :scope => 'returns' return local % [time_until[:hour], time_until[:minute]] end end |