Module: Helpers
- Defined in:
- lib/brewer/helpers.rb
Instance Method Summary collapse
- #adaptibrew_dir(path = "") ⇒ Object
- #brewer_dir(path = "") ⇒ Object
- #capture_stdout(&block) ⇒ Object
- #clear_screen ⇒ Object
- #confirm(input = gets.chomp) ⇒ Object
-
#network? ⇒ Boolean
Returns true if there is a network connection.
-
#time ⇒ Object
Returns the current time Formatted as: 03/07/2017 14:26.
- #to_minutes(seconds) ⇒ Object
- #to_seconds(minutes) ⇒ Object
- #view(view) ⇒ Object
Instance Method Details
#adaptibrew_dir(path = "") ⇒ Object
44 45 46 |
# File 'lib/brewer/helpers.rb', line 44 def adaptibrew_dir(path="") return brewer_dir + "adaptibrew/#{path}" end |
#brewer_dir(path = "") ⇒ Object
40 41 42 |
# File 'lib/brewer/helpers.rb', line 40 def brewer_dir(path="") return Dir.home + "/.brewer/#{path}" end |
#capture_stdout(&block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/brewer/helpers.rb', line 48 def capture_stdout(&block) original_stdout = $stdout $stdout = fake = StringIO.new begin yield ensure $stdout = original_stdout end fake.string end |
#clear_screen ⇒ Object
36 37 38 |
# File 'lib/brewer/helpers.rb', line 36 def clear_screen Gem.win_platform? ? (system "cls") : (system "clear") end |
#confirm(input = gets.chomp) ⇒ Object
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 |
#network? ⇒ Boolean
Returns true if there is a network connection
16 17 18 19 |
# File 'lib/brewer/helpers.rb', line 16 def network? connection = Net::Ping::TCP.new('google.com', 80, 5) connection.ping? end |
#time ⇒ Object
Returns the current time Formatted as: 03/07/2017 14:26
7 8 9 |
# File 'lib/brewer/helpers.rb', line 7 def time Time.now.strftime("%m/%d/%Y %H:%M") end |
#to_minutes(seconds) ⇒ Object
28 29 30 |
# File 'lib/brewer/helpers.rb', line 28 def to_minutes(seconds) seconds.to_f / 60 end |
#to_seconds(minutes) ⇒ Object
32 33 34 |
# File 'lib/brewer/helpers.rb', line 32 def to_seconds(minutes) minutes.to_f * 60 end |
#view(view) ⇒ Object
11 12 13 |
# File 'lib/brewer/helpers.rb', line 11 def view(view) File.open(File.join(__dir__ + "/../../views/#{view}.html.erb")) end |