Class: Rowr::Prompter

Inherits:
Object
  • Object
show all
Defined in:
lib/rowr/prompter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePrompter

Returns a new instance of Prompter.



13
14
15
# File 'lib/rowr/prompter.rb', line 13

def initialize
  @prompt = TTY::Prompt.new
end

Instance Attribute Details

#check_external_urlsObject

Returns the value of attribute check_external_urls.



11
12
13
# File 'lib/rowr/prompter.rb', line 11

def check_external_urls
  @check_external_urls
end

#exts_to_useObject

Returns the value of attribute exts_to_use.



8
9
10
# File 'lib/rowr/prompter.rb', line 8

def exts_to_use
  @exts_to_use
end

#new_base_pathObject

Returns the value of attribute new_base_path.



10
11
12
# File 'lib/rowr/prompter.rb', line 10

def new_base_path
  @new_base_path
end

#old_hostObject

Returns the value of attribute old_host.



9
10
11
# File 'lib/rowr/prompter.rb', line 9

def old_host
  @old_host
end

#source_directoryObject

Returns the value of attribute source_directory.



7
8
9
# File 'lib/rowr/prompter.rb', line 7

def source_directory
  @source_directory
end

Instance Method Details

#additional_exts?Boolean

Returns:



85
86
87
88
# 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_directoryObject



61
62
63
64
65
66
67
68
69
70
# 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?Boolean

Returns:



94
95
96
97
98
99
100
101
# 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_selectObject



52
53
54
55
56
57
58
59
# 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

#generate_hashObject



103
104
105
106
107
108
109
110
111
# 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?Boolean

Returns:



90
91
92
# 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?Boolean

Returns:



72
73
74
# 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?Boolean

Returns:



76
77
78
79
80
81
82
83
# 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