Module: Helpers

Defined in:
lib/brewer/helpers.rb

Overview

Just some helper methods

Instance Method Summary collapse

Instance Method Details

#adaptibrew_dir(path = "") ⇒ Object

Returns the path of the adaptibrew directory ~/.brewer/adaptibrew/



56
57
58
# File 'lib/brewer/helpers.rb', line 56

def adaptibrew_dir(path="")
  brewer_dir + "adaptibrew/#{path}"
end

#brewer_dir(path = "") ⇒ Object

Returns the path of the ~/.brewer directory, where everything is stored



50
51
52
# File 'lib/brewer/helpers.rb', line 50

def brewer_dir(path="")
  Dir.home + "/.brewer/#{path}"
end

#capture_stdout(&block) ⇒ Object

Captures standard output, mostly used for testing :nocov:



67
68
69
70
71
72
73
74
75
76
# File 'lib/brewer/helpers.rb', line 67

def capture_stdout(&block)
  original_stdout = $stdout
  $stdout = fake = StringIO.new
  begin
    yield
  ensure
    $stdout = original_stdout
  end
  fake.string
end

#clear_screenObject

Clears the terminal screen :nocov:



44
45
46
# File 'lib/brewer/helpers.rb', line 44

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



25
26
27
28
29
30
# File 'lib/brewer/helpers.rb', line 25

def confirm(input=gets.chomp)
  if input.to_b
    return true
  end
  false
end

#dd(message = "died here") ⇒ Object



93
94
95
96
# File 'lib/brewer/helpers.rb', line 93

def dd(message="died here")
  puts message
  abort
end

#dummy_recipe_varsObject

:nocov:



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/brewer/helpers.rb', line 79

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

#kitchen_dir(path = "") ⇒ Object

Returns the path of the recipe storage



61
62
63
# File 'lib/brewer/helpers.rb', line 61

def kitchen_dir(path="")
  brewer_dir + "kitchen/#{path}"
end

#network?Boolean

Returns true if there is a network connection :nocov:

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/brewer/helpers.rb', line 18

def network?
  connection = Net::Ping::TCP.new('google.com', 80, 5)
  connection.ping?
end

#timeObject

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



33
34
35
# File 'lib/brewer/helpers.rb', line 33

def to_minutes(seconds)
  seconds.to_f / 60
end

#to_seconds(minutes) ⇒ Object

Converts minutes to seconds



38
39
40
# File 'lib/brewer/helpers.rb', line 38

def to_seconds(minutes)
  minutes.to_f * 60
end

#wait(time = 30) ⇒ Object



12
13
14
# File 'lib/brewer/helpers.rb', line 12

def wait(time=30)
  sleep(time.to_f)
end