Class: GamesAndRpgParadise::Gamebooks::GamebookYamlSection
- Includes:
- Base::ExtensionsForAGamebook
- Defined in:
- lib/games_and_rpg_paradise/gamebooks/gamebook_yaml_section.rb
Overview
GamesAndRpgParadise::Gamebooks::GamebookYamlSection
Constant Summary collapse
- THRESHOLD_N_CHARACTERS =
#
THRESHOLD_N_CHARACTERS
82 should be ok for widescreen monitors really.
#
82
- BASE_DIRECTORY_TO_USE =
#
BASE_DIRECTORY_TO_USE
Specify on which local directory to work on next.
#
'/home/x/Temp/rpg_paradise/lone_wolf_29/sect1.htm'
Constants included from Base::ExtensionsForAGamebook
Base::ExtensionsForAGamebook::DIRECTORY_FOR_THE_GAMEBOOKS
Constants included from CommonExtensions
CommonExtensions::CONTROL_C_CODE, CommonExtensions::N
Constants included from Base::Extensions::Colours
Base::Extensions::Colours::ARRAY_AVAILABLE_KONSOLE_COLOURS
Instance Method Summary collapse
-
#initialize(i = ARGV, run_already = true) ⇒ GamebookYamlSection
constructor
# === initialize ========================================================================= #.
-
#menu(i = commandline_arguments?) ) ⇒ Object
# === menu (menu tag) ========================================================================= #.
-
#parse_this_file(first_argument) ⇒ Object
# === parse_this_file ========================================================================= #.
-
#report_the_result ⇒ Object
# === report_the_result ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#set_base_directory_to_use(i = BASE_DIRECTORY_TO_USE) ⇒ Object
(also: #set_use_this_directory)
# === set_base_directory_to_use ========================================================================= #.
Methods included from Base::ExtensionsForAGamebook
#available_gamebooks?, #io_download, #roll_this_die, use_gtk?, #use_gtk?, #wget, #yaml_gamebooks_dir?
Methods included from Base::Extensions::CommandlineArguments
#commandline_arguments?, #filter_away_commandline_arguments, #first_argument?, #first_non_hyphened_argument?, #set_commandline_arguments
Methods included from CommonExtensions
#cat, #cd, #cliner, #copy_file, #delete, #dirname_but_retains_the_trailing_slash, #disable_colours, #ensure_that_the_log_directory_exists, #esystem, #get_user_input, #infer_the_namespace, #is_on_roebe?, #log_dir?, #mkdir, #mkdir_then_cd_into_it, #mv, #namespace?, #opne, #opnn, #project_base_directory?, #project_image_directory?, #project_yaml_directory?, #rds, #register_sigint, #remove_this_directory, #rename_file, #reset_the_internal_hash, #return_pwd, #return_today, #touch_file, #wrap, #write_what_into
Methods included from Base::Extensions::Colours
ecomment, #efancy, #eparse, #forestgreen, #gold, #grey, #lightblue, #mediumseagreen, #mediumslateblue, #peru, #rev, sdir, sfancy, #sfile, simp, #teal, #yellow
Constructor Details
#initialize(i = ARGV, run_already = true) ⇒ GamebookYamlSection
#
initialize
#
69 70 71 72 73 74 75 76 |
# File 'lib/games_and_rpg_paradise/gamebooks/gamebook_yaml_section.rb', line 69 def initialize( i = ARGV, run_already = true ) reset set_commandline_arguments(i) run if run_already end |
Instance Method Details
#menu(i = commandline_arguments?) ) ⇒ Object
#
menu (menu tag)
#
171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/games_and_rpg_paradise/gamebooks/gamebook_yaml_section.rb', line 171 def (i = commandline_arguments?) if i.is_a? Array i.each {|entry| (entry) } else case i # ===================================================================== # # === gamebook_yaml --use-this-directory=:pwd # ===================================================================== # when /^-?-?use(-|_| )?this(-|_| )?directory=(.+)$/i # === $3 _ = $3.to_s.dup set_use_this_directory(_) end end end |
#parse_this_file(first_argument) ⇒ Object
#
parse_this_file
#
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 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/games_and_rpg_paradise/gamebooks/gamebook_yaml_section.rb', line 108 def parse_this_file(first_argument) unless File.exist?(first_argument) e 'No file exists at '+sfile(first_argument) exit end _dataset = File.read(first_argument) subsection_to_use = first_argument.scan( /(\d+)\.html?/ ).flatten.first.to_s use_this_regex = /<p>(.+\s*)<\/p>/ # See: https://rubular.com/r/UMJFwBfAYQMikf body_content = _dataset.scan(use_this_regex) body_content = body_content.flatten.join("\n") body_content = Cyberweb.remove_html(body_content) body_content = word_wrap(body_content, THRESHOLD_N_CHARACTERS).strip body_content = body_content.lstrip.split("\n").map {|entry| " #{entry}" } body_content = body_content.join("\n") regex_for_exits = /<p class="choice">(.+)<\/p>/ # See: https://rubular.com/r/aX0ct49048lheh exits = _dataset.scan(regex_for_exits).flatten # Now looks like: ["<a href=\"sect273.htm\">Turn to 273</a>."] exits_string = ''.dup exits.each_with_index {|entry, index| index += 1 # "<a href=\"sect273.htm\">Turn to 273</a>." number = entry.scan(/sect(\d+)/).flatten.first.to_s exits_string << " #{number}: |\n" word_wrapped = "#{word_wrap(Cyberweb.remove_html(entry), THRESHOLD_N_CHARACTERS)}".dup if word_wrapped.include?("\n") and word_wrapped.count("\n") > 1 word_wrapped = word_wrapped.split("\n").map {|entry| entry.prepend(" ") }.join("\n") else word_wrapped.prepend(" ") end exits_string << word_wrapped.rstrip+"\n" } # ======================================================================= # # Also remove href-links. # ======================================================================= # @_ = <<-EOF # =========================================================================== # # === #{subsection_to_use} # =========================================================================== # #{subsection_to_use}: content: | #{body_content} exits: #{exits_string} EOF end |
#report_the_result ⇒ Object
#
report_the_result
#
164 165 166 |
# File 'lib/games_and_rpg_paradise/gamebooks/gamebook_yaml_section.rb', line 164 def report_the_result e @_ end |
#reset ⇒ Object
#
reset (reset tag)
#
81 82 83 84 85 86 87 |
# File 'lib/games_and_rpg_paradise/gamebooks/gamebook_yaml_section.rb', line 81 def reset @_ = ''.dup # ======================================================================= # # === @base_directory_to_use # ======================================================================= # set_base_directory_to_use(BASE_DIRECTORY_TO_USE) end |
#run ⇒ Object
#
run (run tag)
#
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/games_and_rpg_paradise/gamebooks/gamebook_yaml_section.rb', line 189 def run first_argument = first_non_hyphened_argument?.to_s if is_on_roebe? and (first_argument..nil? or first_argument.empty?) first_argument = '1-350' # e 'Using '+first_argument+' as default value.' end if first_argument and first_argument.include?('-') # ===================================================================== # # This entry-point is for when the input will be a range, such as # 100-200. # ===================================================================== # # gamebookyamlsection 104-350 splitted = first_argument.split('-') start_page = splitted.first.to_i end_page = splitted.last.to_i index = 0 # Iterate over the result. start_page.upto(end_page) {|this_page| index += 1 page_name = File.basename(@base_directory_to_use.to_s). sub(/(\d+)/, this_page.to_s) local_file = File.dirname(@base_directory_to_use)+'/'+page_name unless File.file?(page_name) # Try 'sect'NUMBER'.htm' instead. page_name = @base_directory_to_use.to_s+'sect'+index.to_s+'.htm' local_file = page_name.dup end parse_this_file(local_file) report_the_result } elsif first_argument and File.exist?(first_argument) parse_this_file(first_argument) report_the_result end end |
#set_base_directory_to_use(i = BASE_DIRECTORY_TO_USE) ⇒ Object Also known as: set_use_this_directory
#
set_base_directory_to_use
#
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/games_and_rpg_paradise/gamebooks/gamebook_yaml_section.rb', line 92 def set_base_directory_to_use( i = BASE_DIRECTORY_TO_USE ) case i # ======================================================================= # # === :pwd # ======================================================================= # when :pwd, 'pwd',':pwd' i = return_pwd end @base_directory_to_use = i end |