Module: Helpers
- Defined in:
- lib/brewer/helpers.rb
Overview
Just some helper methods
Instance Method Summary collapse
-
#adaptibrew_dir(path = "") ⇒ Object
Returns the path of the adaptibrew directory ~/.brewer/adaptibrew/.
-
#brewer_dir(path = "") ⇒ Object
Returns the path of the ~/.brewer directory, where everything is stored.
-
#capture_stdout(&block) ⇒ Object
Captures standard output, mostly used for testing :nocov:.
-
#clear_screen ⇒ Object
Clears the terminal screen :nocov:.
-
#confirm(input = gets.chomp) ⇒ Object
waits for user input, if ‘y’ return true, else return false.
-
#dummy_recipe_vars ⇒ Object
:nocov:.
-
#network? ⇒ Boolean
Returns true if there is a network connection :nocov:.
-
#recipe_dir(path = "") ⇒ Object
Returns the path of the recipe storage.
-
#time ⇒ Object
Returns the current time Formatted as: 03/07/2017 14:26.
-
#to_minutes(seconds) ⇒ Object
Converts seconds to minutes.
-
#to_seconds(minutes) ⇒ Object
Converts minutes to seconds.
Instance Method Details
#adaptibrew_dir(path = "") ⇒ Object
Returns the path of the adaptibrew directory ~/.brewer/adaptibrew/
52 53 54 |
# File 'lib/brewer/helpers.rb', line 52 def adaptibrew_dir(path="") brewer_dir + "adaptibrew/#{path}" end |
#brewer_dir(path = "") ⇒ Object
Returns the path of the ~/.brewer directory, where everything is stored
46 47 48 |
# File 'lib/brewer/helpers.rb', line 46 def brewer_dir(path="") Dir.home + "/.brewer/#{path}" end |
#capture_stdout(&block) ⇒ Object
Captures standard output, mostly used for testing :nocov:
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/brewer/helpers.rb', line 63 def capture_stdout(&block) original_stdout = $stdout $stdout = fake = StringIO.new begin yield ensure $stdout = original_stdout end fake.string end |
#clear_screen ⇒ Object
Clears the terminal screen :nocov:
40 41 42 |
# File 'lib/brewer/helpers.rb', line 40 def clear_screen Gem.win_platform? ? (system "cls") : (system "clear") end |
#confirm(input = gets.chomp) ⇒ Object
waits for user input, if ‘y’ return true, else return false
21 22 23 24 25 26 |
# File 'lib/brewer/helpers.rb', line 21 def confirm(input=gets.chomp) if input.to_b return true end false end |
#dummy_recipe_vars ⇒ Object
:nocov:
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/brewer/helpers.rb', line 75 def dummy_recipe_vars return { 'name' => "dummy_recipe", 'mash_temp' => 150, 'mash_time' => 10, 'mashout_temp' => 172, 'water' => 14, 'grain' => 5, 'grain_temp' => 80.1, 'desired_mash_temp' => 150, 'strike_water_temp' => 168.6, } end |
#network? ⇒ Boolean
Returns true if there is a network connection :nocov:
14 15 16 17 |
# File 'lib/brewer/helpers.rb', line 14 def network? connection = Net::Ping::TCP.new('google.com', 80, 5) connection.ping? end |
#recipe_dir(path = "") ⇒ Object
Returns the path of the recipe storage
57 58 59 |
# File 'lib/brewer/helpers.rb', line 57 def recipe_dir(path="") brewer_dir + "recipes/#{path}" end |
#time ⇒ Object
Returns the current time Formatted as: 03/07/2017 14:26
8 9 10 |
# File 'lib/brewer/helpers.rb', line 8 def time Time.now.strftime("%m/%d/%Y %H:%M") end |
#to_minutes(seconds) ⇒ Object
Converts seconds to minutes
29 30 31 |
# File 'lib/brewer/helpers.rb', line 29 def to_minutes(seconds) seconds.to_f / 60 end |
#to_seconds(minutes) ⇒ Object
Converts minutes to seconds
34 35 36 |
# File 'lib/brewer/helpers.rb', line 34 def to_seconds(minutes) minutes.to_f * 60 end |