Module: Kuport::Helper
- Included in:
- Kuport
- Defined in:
- lib/kuport/helper.rb
Instance Method Summary collapse
- #color_str(color_num, str) ⇒ Object
- #get_page_doc(page) ⇒ Object
- #input_num(str) ⇒ Object
- #input_passwd ⇒ Object
- #quit(mes, ret = false) ⇒ Object
- #to_abs_url(base, part) ⇒ Object
Instance Method Details
#color_str(color_num, str) ⇒ Object
11 12 13 |
# File 'lib/kuport/helper.rb', line 11 def color_str(color_num, str) "\e[38;5;#{color_num}m#{str}\e[00m" end |
#get_page_doc(page) ⇒ Object
15 16 17 |
# File 'lib/kuport/helper.rb', line 15 def get_page_doc(page) Nokogiri::HTML.parse(page.content.toutf8) end |
#input_num(str) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/kuport/helper.rb', line 19 def input_num(str) print str gets.to_i rescue nil rescue Interrupt exit 1 end |
#input_passwd ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/kuport/helper.rb', line 26 def input_passwd $stderr.print 'Password> ' pass = STDIN.noecho(&:gets).chomp rescue nil # &.chomp puts return pass rescue Interrupt exit 2 end |
#quit(mes, ret = false) ⇒ Object
35 36 37 38 |
# File 'lib/kuport/helper.rb', line 35 def quit(mes, ret=false) warn mes exit ret end |
#to_abs_url(base, part) ⇒ Object
5 6 7 8 9 |
# File 'lib/kuport/helper.rb', line 5 def to_abs_url(base, part) uri = URI.parse(part) uri = URI.join(base, uri) if URI::Generic === uri uri.to_s end |