Class: Roebe::InteractiveFileCreator

Inherits:
Base show all
Defined in:
lib/roebe/classes/interactive_file_creator.rb

Overview

Roebe::InteractiveFileCreator

Constant Summary collapse

ASK_FOR_FILE_SUFFIX =
#

ASK_FOR_FILE_SUFFIX

#
true

Constants inherited from Base

Base::COLOURS, Base::HOME_DIRECTORY_OF_USER_X, Base::N, Base::NAMESPACE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#actions, #append_this_onto_that_file, #append_what_into, #be_silent, #be_verbose?, #beautiful_url, #burlywood, #call_next, #chdir, #cheerful_guy, #cliner, #complex_esystem, #convert_global_env, #copy_directory, #copy_file, #cornflowerblue, #create_directory, #crimson, #current_month?, #current_time?, #current_year?, #cyan, #darkcyan, #darkgreen, #darkkhaki, #darkslateblue, #deeppink, #delete_symlink, #do_not_use_the_base_colours, #do_use_the_base_colours, #e, #ecomment, #editor_to_use?, #efancy, #eimp, #emphasis, #ensure_main_encoding, #ensure_utf_encoding, #eparse, #erev, #esteelblue, #etomato, #ewarn, #exit_program, #firebrick, #get_current_day, #get_current_month, #get_files_and_directories, #get_files_from, #get_german_name_for_this_weekday, #gold, #green, #grey, #hh_mm_ss, #hh_mm_ss_day_month_year, #home_dir?, #home_directory_of_user_x?, #infer_the_namespace, #internal_hash?, #is_a_directory?, #is_a_file?, #is_a_jpg_file?, #is_an_image_file?, #is_archive?, #is_audio_file?, #is_in_studium_dir?, #is_multimedia_file?, #is_on_roebe?, #is_on_windows?, #is_studium_available?, #is_symlink?, #is_this_a_ruby_file?, #is_video_file?, #iso_encoding?, #le, #left_colour, #lightblue, #lightgreen, #lightseagreen, #lightsteelblue, #lime, #limegreen, #localhost_to_data, #log_directory?, #main_encoding?, #mediumorchid, #mediumpurple, #mediumseagreen, #mediumslateblue, #mediumspringgreen, #mediumturquoise, #mkdir_p, #mv, #n_days_in_this_month, #n_pages_in_this_pdf_file?, #namespace?, #no_file_exists_at, #ogrey, #olive, #olivedrab, #open_in_browser, #opne, #opnesystem, #opnn, #orange, #orchid, #orev, #palegoldenrod, #palevioletred, #pink, #powderblue, #programs_dir?, #project_base_dir?, #random_html_colour, #rds, #read_file_in_iso_encoding, #read_file_via_the_default_encoding, #read_lines_via_iso_encoding, #readlines_with_main_encoding, #red, #register_sigint, #remove, #remove_directory, #remove_file, #rename_kde_konsole_tab, #replace_localhost_with_data, #report_pwd, #require_rescue, #reset_the_internal_hash, #return_all_directories_from_this_directory, #return_all_files_from_this_directory, #return_current_directory, #return_dd_mm_yyyy, #return_file_or_directory_of, #return_files_from_pwd, #return_last_part_of_the_current_directory, #return_utc, #rev, #right_arrow?, #right_colour, #roebe_log_directory?, #rosybrown, #royalblue, #ruby_base_directory?, #run_in_background, #run_rcfiles_then_run_ata_via_qdbus, #sandybrown, #sdir, #seagreen, #set_be_verbose, #set_xorg_buffer, #sfancy, #sfile, #show_help, #silent_redirection?, #simp, #simple_esystem, #skyblue, #slateblue, #slategray, #springgreen, #steelblue, #string_italic, #swarn, #symlink, #teal, #temp_dir?, #to_camelcase, #to_counted_hash, #tomato, #try_to_require_the_beautiful_url_gem, #try_to_require_the_html_template, #try_to_require_the_open_gem, #try_to_require_the_program_information_gem, #try_to_require_the_xorg_buffer, #use_colours?, #verbose_truth, #weekday?, #word_wrap, #write_what_into, #yellow

Methods included from Base::CommandlineArguments

#append_onto_the_commandline_arguments, #clear_commandline_arguments, #commandline_arguments?, #commandline_arguments_as_string?, #commandline_arguments_without_leading_hyphens?, #first_argument?, #first_argument_without_leading_hyphens?, #has_an_argument_been_passed?, #remove_hyphened_arguments_from_the_commandline_arguments, #return_commandline_arguments_with_leading_hyphens, #second_argument?, #set_commandline_arguments

Constructor Details

#initialize(run_already = true) ⇒ InteractiveFileCreator

#

initialize

#


32
33
34
35
36
37
# File 'lib/roebe/classes/interactive_file_creator.rb', line 32

def initialize(
    run_already = true
  )
  reset
  run if run_already
end

Class Method Details

.[](i = ARGV) ⇒ Object

#

[]

#


214
215
216
# File 'lib/roebe/classes/interactive_file_creator.rb', line 214

def self.[](i = ARGV)
  new(i)
end

Instance Method Details

#ask_for_file_suffix?Boolean

#

ask_for_file_suffix?

#

Returns:

  • (Boolean)


152
153
154
# File 'lib/roebe/classes/interactive_file_creator.rb', line 152

def ask_for_file_suffix?
  ASK_FOR_FILE_SUFFIX
end

#create_the_filesObject

#

create_the_files

#


159
160
161
162
163
164
165
166
167
168
# File 'lib/roebe/classes/interactive_file_creator.rb', line 159

def create_the_files
  @start_where.upto(@end_where).each {|index_number|
    _ = name_of_the_file+'_'
    _ << index_number.to_s.rjust(@end_where.to_s.size,'0')
    if ASK_FOR_FILE_SUFFIX
      _ << @file_suffix
    end
    touch _, :be_verbose
  }
end

#name_of_the_fileObject

#

name_of_the_file

#


194
195
196
# File 'lib/roebe/classes/interactive_file_creator.rb', line 194

def name_of_the_file
  @name_of_the_file_that_will_be_created
end

#number_fourObject

#

number_four

#


75
76
77
# File 'lib/roebe/classes/interactive_file_creator.rb', line 75

def number_four
  yellow('4')
end

#number_oneObject

#

number_one

#


54
55
56
# File 'lib/roebe/classes/interactive_file_creator.rb', line 54

def number_one
  yellow('1')
end

#number_threeObject

#

number_three

#


68
69
70
# File 'lib/roebe/classes/interactive_file_creator.rb', line 68

def number_three
  yellow('3')
end

#number_twoObject

#

number_two

#


61
62
63
# File 'lib/roebe/classes/interactive_file_creator.rb', line 61

def number_two
  yellow('2')
end

#resetObject

#

reset (reset tag)

#


42
43
44
45
46
47
48
49
# File 'lib/roebe/classes/interactive_file_creator.rb', line 42

def reset
  super()
  infer_the_namespace
  @start_where =  0 # Default start setting.
  @end_where   = 20 # Default end   setting.
  @name_of_the_file_that_will_be_created = 'foobar.md'
  @file_suffix = ''.dup
end

#return_user_input(optional_use_this_as_default_if_user_hits_enter = nil) ⇒ Object

#

return_user_input

#


201
202
203
204
205
206
207
208
209
# File 'lib/roebe/classes/interactive_file_creator.rb', line 201

def return_user_input(
    optional_use_this_as_default_if_user_hits_enter = nil
  )
  user_input = $stdin.gets.chomp
  if user_input.empty? and optional_use_this_as_default_if_user_hits_enter
    user_input = optional_use_this_as_default_if_user_hits_enter
  end
  user_input
end

#runObject

#

run (run tag)

#


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/roebe/classes/interactive_file_creator.rb', line 103

def run
  e 'Some questions will be asked next.'
  e
  default_file_name = nil
  # ======================================================================= #
  # === (1)
  # ======================================================================= #
  ask_this_question = '('+number_one+') What is the '+powderblue('name')+' of the file '\
    'that is to be created?'
  # ======================================================================= #
  # If the user is in the ascii_paradise directory, then we will
  # also assume some default.
  # ======================================================================= #
  if return_pwd.include? 'ascii_paradise'
    default_file_name = File.basename(return_pwd)
    ask_this_question << ' (If you just hit enter,'+N
    ask_this_question << 'we will assume the default file name '\
                         'being '+skyblue('->')+
                         ' '+sfile(default_file_name)+')'
  end
  e ask_this_question
  set_name_of_the_file(
    return_user_input(default_file_name)
  )
  # ======================================================================= #
  # === (2)
  # ======================================================================= #
  e '('+number_two+') At which position will we '+powderblue('start')+'? '\
    '('+lightgreen('1')+' may be a good default to pick here)'
  set_start_where(return_user_input)
  # ======================================================================= #
  # === (3)
  # ======================================================================= #
  e '('+number_three+') At which position will we '+powderblue('end')+'?'
  set_end_where(return_user_input)
  if ask_for_file_suffix?
    e '('+number_four+') Input the name for the '+powderblue('file suffix')+
      ' next. (Just press enter if you do not need a file suffix.)'
    set_file_suffix(return_user_input)
  end
  e
  e 'We will next create the '+sfancy(@end_where.to_s)+' files.'
  e
  create_the_files
end

#set_end_where(i) ⇒ Object

#

set_end_where

#


173
174
175
# File 'lib/roebe/classes/interactive_file_creator.rb', line 173

def set_end_where(i)
  @end_where = i.to_i
end

#set_file_suffix(i = '') ⇒ Object

#

set_file_suffix

#


95
96
97
98
# File 'lib/roebe/classes/interactive_file_creator.rb', line 95

def set_file_suffix(i = '')
  i.chomp! # Don't want any newlines there.
  @file_suffix = i
end

#set_name_of_the_file_that_will_be_created(i) ⇒ Object Also known as: set_name_of_the_file

#

set_name_of_the_file_that_will_be_created

#


187
188
189
# File 'lib/roebe/classes/interactive_file_creator.rb', line 187

def set_name_of_the_file_that_will_be_created(i)
  @name_of_the_file_that_will_be_created = i
end

#set_start_where(i) ⇒ Object

#

set_start_where

#


180
181
182
# File 'lib/roebe/classes/interactive_file_creator.rb', line 180

def set_start_where(i)
  @start_where = i.to_i
end

#touch(name_of_the_file, be_verbose = :be_verbose) ⇒ Object

#

touch

#


82
83
84
85
86
87
88
89
90
# File 'lib/roebe/classes/interactive_file_creator.rb', line 82

def touch(
    name_of_the_file,
    be_verbose = :be_verbose
  )
  if be_verbose
    e rev+'Next creating file `'+sfile(name_of_the_file)+rev+'`.'
  end
  FileUtils.touch(name_of_the_file)
end