Module: Kuport::Helper

Included in:
Kuport
Defined in:
lib/kuport/helper.rb

Instance Method Summary collapse

Instance Method Details

#basename_noext(path) ⇒ Object



3
4
5
# File 'lib/kuport/helper.rb', line 3

def basename_noext(path)
  File.basename(path, File.extname(path))
end

#blank?(var) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/kuport/helper.rb', line 54

def blank?(var)
  var.nil? || var.empty?
end

#br_to_return(element) ⇒ Object



7
8
9
# File 'lib/kuport/helper.rb', line 7

def br_to_return(element)
  element.search('br').each{|br| br.replace("\n")}
end

#color_str(color_num, str) ⇒ Object



17
18
19
# File 'lib/kuport/helper.rb', line 17

def color_str(color_num, str)
  "\e[38;5;#{color_num}m#{str}\e[00m"
end

#get_page_doc(page) ⇒ Object



21
22
23
# File 'lib/kuport/helper.rb', line 21

def get_page_doc(page)
  Nokogiri::HTML.parse(page.content.toutf8)
end

#input_num(str) ⇒ Object



33
34
35
36
37
38
# File 'lib/kuport/helper.rb', line 33

def input_num(str)
  print str
  gets.to_i rescue nil
rescue Interrupt
  exit 1
end

#input_passwdObject



40
41
42
43
44
45
46
47
# File 'lib/kuport/helper.rb', line 40

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



49
50
51
52
# File 'lib/kuport/helper.rb', line 49

def quit(mes, ret=false)
  warn mes
  exit ret
end

#to_abs_url(base, part) ⇒ Object



11
12
13
14
15
# File 'lib/kuport/helper.rb', line 11

def to_abs_url(base, part)
  uri = URI.parse(part)
  uri = URI.join(base, uri) if URI::Generic === uri
  uri.to_s
end

#to_half_str(str) ⇒ Object



25
26
27
# File 'lib/kuport/helper.rb', line 25

def to_half_str(str)
  NKF.nkf('-m0Z1 -w -W', str)
end

#url?(str) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/kuport/helper.rb', line 29

def url?(str)
  str =~ /\A#{URI::regexp}\z/
end