class Rowr::Prompter

Attributes

check_external_urls[RW]
exts_to_use[R]
new_base_path[R]
old_host[R]
source_directory[R]

Public Class Methods

new() click to toggle source
# File lib/rowr/prompter.rb, line 13
def initialize
  @prompt = TTY::Prompt.new
end

Public Instance Methods

additional_exts?() click to toggle source
# File lib/rowr/prompter.rb, line 85
def additional_exts?
  @prompt.say('By default, I\'ll will scan any .html and .htm files.')
  self.exts_to_use  = @prompt.ask('Please list any other extensions, or hit Enter to skip')
end
ask_for_other_source_directory() click to toggle source
# File lib/rowr/prompter.rb, line 61
def ask_for_other_source_directory
  dir = @prompt.ask('Please type in the path to that directory?') do |q|
    q.required true
  end
  unless Dir.exist?(File.expand_path(dir))
    @prompt.error("Sorry, #{dir} doesn't seem to exist")
    ask_for_other_source_directory
  end
  dir
end
check_external_urls?() click to toggle source
# File lib/rowr/prompter.rb, line 94
def check_external_urls?
  self.check_external_urls = @prompt.select('If I find an link to an external site, what should I do?') do |menu|
    menu.default 1

    menu.choice 'Ask me about it', true
    menu.choice 'Skip it', false
  end
end
dir_select() click to toggle source
# File lib/rowr/prompter.rb, line 52
def dir_select
  @prompt.select('Where is this really old website?') do |menu|
    menu.default 1

    menu.choice "#{Dir.pwd} (The current dir)", 1
    menu.choice "Another directory?", 2
  end
end
exts_to_use=(value) click to toggle source
# File lib/rowr/prompter.rb, line 30
def exts_to_use=(value)
  exts = []
  if value
    exts = value.split
    exts.map! { |e| e.start_with?('.') ? e[1..-1] : e } if exts.is_a?(Array)
  end
  exts = %w(htm html) + exts
  @exts_to_use = exts.uniq
end
generate_hash() click to toggle source
# File lib/rowr/prompter.rb, line 103
def generate_hash
  {
    source_directory: source_directory,
    exts_to_use: exts_to_use,
    old_host: old_host,
    new_base_path: new_base_path,
    check_external_urls: check_external_urls
  }
end
new_base_path=(value) click to toggle source
# File lib/rowr/prompter.rb, line 40
def new_base_path=(value)
  clean = ''
  unless value.to_s.empty?
    clean = value.sub(%r{https?://(.*?)(/|$)}, '')
    clean = clean.split('/')
    clean = clean.reject(&:empty?)
    clean.shift if clean.first =~ /\./
    clean = clean.join('/')
  end
  @new_base_path = clean.to_s.empty? ? '/' : "/#{clean}/"
end
new_base_path?() click to toggle source
# File lib/rowr/prompter.rb, line 90
def new_base_path?
  self.new_base_path = @prompt.ask('What will be the url of the resurrected site?')
end
old_host=(value) click to toggle source
# File lib/rowr/prompter.rb, line 22
def old_host=(value)
  if value.to_s.empty?
    @old_host = false
  else
    @old_host = value.chomp('/').chomp('/').sub(%r{https?://}, '')
  end
end
old_host?() click to toggle source
# File lib/rowr/prompter.rb, line 72
def old_host?
  self.old_host = @prompt.ask('What was the old host? (e.g. www.google.com)')
end
source_directory=(value) click to toggle source
# File lib/rowr/prompter.rb, line 17
def source_directory=(value)
  dir = File.expand_path(value)
  @source_directory = dir if Dir.exist?(dir)
end
source_directory?() click to toggle source
# File lib/rowr/prompter.rb, line 76
def source_directory?
  self.source_directory = case dir_select
                          when 1
                            Dir.pwd
                          when 2
                            ask_for_other_source_directory
                          end
end