class Gemsearch::Utils
Attributes
prompt[R]
spinner[R]
spinner_enabled[R]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/gemsearch/utils.rb, line 5 def initialize(opts = {}) @prompt = opts.fetch(:prompt) { TTY::Prompt.new } @spinner_enabled = opts.fetch(:spinner_enabled) { true } @spinner = opts.fetch(:spinner) end
Public Instance Methods
humanize_number(n)
click to toggle source
# File lib/gemsearch/utils.rb, line 11 def humanize_number(n) HumanizeNumber.humanize(n) end
remove_special_characters(string)
click to toggle source
# File lib/gemsearch/utils.rb, line 15 def remove_special_characters(string) string.gsub(/[\n\t\r]/, '') end
temp_hide_cursor() { || ... }
click to toggle source
# File lib/gemsearch/utils.rb, line 23 def temp_hide_cursor hide_cursor yield rescue TTY::Reader::InputInterrupt, Interrupt exit ensure show_cursor end
truncate(text, n)
click to toggle source
# File lib/gemsearch/utils.rb, line 19 def truncate(text, n) text.gsub(/^(.{#{n - 4},}?).*$/m,'\1...') end
with_spinner() { || ... }
click to toggle source
# File lib/gemsearch/utils.rb, line 32 def with_spinner spinner.auto_spin if spinner_enabled yield spinner.stop if spinner_enabled end
Private Instance Methods
hide_cursor()
click to toggle source
# File lib/gemsearch/utils.rb, line 44 def hide_cursor $stdout.print(prompt.hide) end
show_cursor()
click to toggle source
# File lib/gemsearch/utils.rb, line 48 def show_cursor $stdout.print(prompt.show) end