class CaseParser
#¶ ↑
Constants
- DEFAULT_FILE
#¶ ↑
Test it via compile.rb.
#¶ ↑
- SHALL_WE_DEBUG
#¶ ↑
SHALL_WE_DEBUG
¶ ↑#¶ ↑
- USE_THIS_ENCODING
#¶ ↑
USE_THIS_ENCODING
¶ ↑#¶ ↑
- VERSION
#¶ ↑
VERSION
¶ ↑#¶ ↑
Public Class Methods
new( i = DEFAULT_FILE, run_already = true )
click to toggle source
parse(i, optional_run_already = :do_not_exit)
click to toggle source
Public Instance Methods
append_to_main_array(i)
click to toggle source
dataset?()
click to toggle source
extract_first_when( mode = :extract_only_first_entry )
click to toggle source
#¶ ↑
extract_first_when
¶ ↑
Use this method here if you wish to extract the first word.
#¶ ↑
# File lib/case_parser/case_parser.rb, line 209 def extract_first_when( mode = :extract_only_first_entry ) dataset?.each { |d| if d.include? 'when' # Work on when-entries only. This is not perfect, as we miss other entries. begin _ = d.chomp.strip.gsub(/when /,'') # Eliminate 'when ' here. rescue ArgumentError opn; e 'ArgumentError - invalid byte sequence in US-ASCII' end if _ _ = _.split(',') if _.include? ',' # Split on ',' if they exist. _ = _.delete("'") if _.include? "'" # Eliminate "'" characters. append_to_main_array(_) end end } end
feedback()
click to toggle source
found_entries?()
click to toggle source
read_file()
click to toggle source
#¶ ↑
read_file
¶ ↑
#¶ ↑
# File lib/case_parser/case_parser.rb, line 173 def read_file if File.exist? @file @dataset = File.readlines(@file, encoding: USE_THIS_ENCODING) else if @may_we_exit_on_missing_file opn; e red+'Can not continue. File `'+sfile(@file)+ red+'` does not exist.'+rev exit end end if @shall_we_debug opn; pp dataset? end end
red()
click to toggle source
remove_potential_comments(i)
click to toggle source
report_n_entries()
click to toggle source
reset()
click to toggle source
#¶ ↑
reset ¶ ↑
#¶ ↑
# File lib/case_parser/case_parser.rb, line 96 def reset # ======================================================================== # # === @dataset # ======================================================================== # @dataset = nil # ======================================================================== # # === @seen_case # # Whether we saw "case" yet or did not. # ======================================================================== # @seen_case = false # ======================================================================== # # === @array_keeping_all_when_entries # ======================================================================== # @array_keeping_all_when_entries = [] # ======================================================================== # # === @shall_we_debug # # If true then we will debug. # ======================================================================== # @shall_we_debug = SHALL_WE_DEBUG # ======================================================================== # # === @may_we_exit_on_missing_file # ======================================================================== # @may_we_exit_on_missing_file = true end
results()
click to toggle source
run(which_file)
click to toggle source
sanitize_array()
click to toggle source
#¶ ↑
sanitize_array
¶ ↑
This will try to sanitize the array.
#¶ ↑
# File lib/case_parser/case_parser.rb, line 135 def sanitize_array @array_keeping_all_when_entries.flatten! begin # Musct rescue this in case the encoding is bad. @array_keeping_all_when_entries.map! {|entry| entry.delete("'").strip } rescue; end # ======================================================================== # # Now, we remove all Regexes from this menu, because Regexes # are not really useful to keep for tab completion in most # scripts. # ======================================================================== # @array_keeping_all_when_entries.reject! {|entry| entry.start_with? '/' or entry.start_with? ':' # Symbols also get rejected. } end
set_file(i)
click to toggle source
#¶ ↑
set_file
¶ ↑
Simply set the @file variable here.
#¶ ↑
# File lib/case_parser/case_parser.rb, line 69 def set_file(i) i = DEFAULT_FILE if i.nil? case i # ======================================================================== # # === :beautiful_menu # ======================================================================== # when :beautiful_menu i = ConvertGlobalEnv[ '$RUBY_SRC/beautiful_url/lib/beautiful_url/toplevel_methods/menu.rb' ] # Hardcoded. unless File.exist? i opn; e 'Warning - no file exists at `'+sfile(i)+'`.' end when :dia_menu i = ConvertGlobalEnv['$RUBY_SRC/diamond_shell/lib/diamond_shell/menu/menu.rb'] unless File.exist? i opn; e 'Warning - no file exists at `'+sfile(i)+'`.' end end i = i.to_s unless i.is_a? String i = ConvertGlobalEnv.convert(i) if i.include? '$' @file = i end