module Kuport::Helper
Public Instance Methods
clear_proxy_env_var()
click to toggle source
# File lib/kuport/helper.rb, line 60 def clear_proxy_env_var ENV.delete_if{|k,v| k =~ /_proxy/i } end
color_str(color_num, str)
click to toggle source
# File lib/kuport/helper.rb, line 17 def color_str(color_num, str) "\e[38;5;#{color_num}m#{str}\e[00m" end
escape_filename(filename)
click to toggle source
# File lib/kuport/helper.rb, line 13 def escape_filename(filename) File.basename(filename.strip) end
get_page_doc(page)
click to toggle source
# File lib/kuport/helper.rb, line 21 def get_page_doc(page) Nokogiri::HTML.parse(page.content.toutf8) end
get_proxy_env_var()
click to toggle source
# File lib/kuport/helper.rb, line 46 def get_proxy_env_var keys = %w[ http_proxy https_proxy all_proxy ].map{|s| [s, s.upcase]}.flatten keys.each do |key| return ENV[key] if ENV.key?(key) end return nil end
input_num(str)
click to toggle source
# File lib/kuport/helper.rb, line 25 def input_num(str) print str gets.to_i rescue nil rescue Interrupt exit 1 end
input_passwd()
click to toggle source
# File lib/kuport/helper.rb, line 32 def input_passwd $stderr.print 'Password> ' pass = STDIN.noecho(&:gets).chomp rescue nil # &.chomp puts return pass rescue Interrupt exit 2 end
parse_proxy_str(str)
click to toggle source
# File lib/kuport/helper.rb, line 54 def parse_proxy_str(str) str = 'http://' + str if str !~ /\A\w+:\/\// u = URI.parse(str) [u.host, u.port] end
quit(mes, ret=false)
click to toggle source
# File lib/kuport/helper.rb, line 41 def quit(mes, ret=false) warn mes exit ret end
to_abs_url(base, part)
click to toggle source
# File lib/kuport/helper.rb, line 7 def to_abs_url(base, part) uri = URI.parse(part) uri = URI.join(base, uri) if URI::Generic === uri uri.to_s end