Class: Cyberweb::CopyAllImagesFromThisWebpageToTheCurrentWorkingDirectory
- Inherits:
-
Base
- Object
- Base
- Cyberweb::CopyAllImagesFromThisWebpageToTheCurrentWorkingDirectory
- Defined in:
- lib/cyberweb/utility_scripts/copy_all_images_from_this_webpage_to_the_current_working_directory.rb
Overview
Foo::CopyAllImagesFromThisWebpageToTheCurrentWorkingDirectory
Constant Summary collapse
- IMAGE_DIRECTORY =
#
IMAGE_DIRECTORY
#
Cyberweb.roebe_image_dir?
- RELATIVE_IMAGE_DIRECTORY =
#
RELATIVE_IMAGE_DIRECTORY
#
Cyberweb.home_x_dir?
Constants inherited from Base
Base::HOME_DIRECTORY_OF_THE_USER_X, Base::NAMESPACE
Class Method Summary collapse
-
.[](i = ARGV) ⇒ Object
# === Cyberweb::CopyAllImagesFromThisWebpageToTheCurrentWorkingDirectory[] ========================================================================= #.
Instance Method Summary collapse
-
#copy_this_image(i) ⇒ Object
# === copy_this_image ========================================================================= #.
-
#download_this_image(i) ⇒ Object
# === download_this_image ========================================================================= #.
-
#initialize(commandline_arguments = nil, run_already = true) ⇒ CopyAllImagesFromThisWebpageToTheCurrentWorkingDirectory
constructor
# === initialize ========================================================================= #.
-
#prepare_these_images(i) ⇒ Object
# === prepare_these_images ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
Methods inherited from Base
#be_verbose, #be_verbose?, #cascading_style_sheets_directory?, #cd, #commandline_mode?, #copyright?, #css_comment, #delete_directory, #do_toggle, #e, #echo_raw, #filename?, #full_path_to_image_directory?, #html_colours?, #html_image, #htmlentities, #img_dir?, #infer_the_namespace, #initialize_the_configuration, #is_a_file?, #is_a_video_file?, #is_an_image_file?, #is_on_roebe?, #last_tag_used?, #last_tag_used_first_element?, #last_tag_used_id?, #mkdir, #mode?, #namespace?, #open_in_browser, #opne, #opnn, #remove_comments_from_this_string_but_preserve_CSS_rules, #remove_html, #return_all_directories, #return_date, #return_program_name, #return_pwd, #ruby_header?, #server_base_directory?, #set_commandline_mode, #set_last_tag_used, #update_the_image_directory, #use_this_relative_directory_for_custom_images?, #www_mode?
Methods included from BaseModule::FileRelatedFunctionality
#copy_this_file, #cpr, #delete_file, #filename_without_extension?, #read_file_via_utf8_encoding
Methods included from BaseModule
#attach_these_constants, #base_dir?, #beautiful_url, #cd, #create_the_internal_hash, #doctype?, #ee, #ensure_main_encoding, #esystem, #html_templates, #initialize_the_config_if_the_config_hash_is_empty, #internal_hash?, #log_dir?, #no_http, #random_alphabet_characters, #rarrow?, #rds, #remove_comments_from_this_string, #remove_numbers, #require_the_html_templates, #require_these, #return_file_size_in_kb_of, #return_html_comment, #ruby_sitelib_dir?, #sanitize_this_id, #server_base_directory?, #string_remote_image, #today?, #try_to_require_rack, #try_to_require_the_open_gem, #write_what_into
Methods included from BaseModule::ContentType
#content_type_is_html, #content_type_is_jpeg, #content_type_is_json, #content_type_is_plain_text
Methods included from BaseModule::CommandlineArguments
#append_to_the_commandline_arguments, #commandline_arguments?, #first_argument?, #parse_these_commandline_arguments, #second_argument?, #set_commandline_arguments
Methods included from BaseModule::Colours
#all_html_colours, #lightgreen, #rev, #sdir, #sfancy, #sfile, #simp, #steelblue, #tomato
Constructor Details
#initialize(commandline_arguments = nil, run_already = true) ⇒ CopyAllImagesFromThisWebpageToTheCurrentWorkingDirectory
#
initialize
#
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cyberweb/utility_scripts/copy_all_images_from_this_webpage_to_the_current_working_directory.rb', line 38 def initialize( commandline_arguments = nil, run_already = true ) reset set_commandline_arguments( commandline_arguments ) run if run_already end |
Class Method Details
Instance Method Details
#copy_this_image(i) ⇒ Object
#
copy_this_image
#
96 97 98 |
# File 'lib/cyberweb/utility_scripts/copy_all_images_from_this_webpage_to_the_current_working_directory.rb', line 96 def copy_this_image(i) FileUtils.copy(i, Dir.pwd) end |
#download_this_image(i) ⇒ Object
#
download_this_image
#
60 61 62 |
# File 'lib/cyberweb/utility_scripts/copy_all_images_from_this_webpage_to_the_current_working_directory.rb', line 60 def download_this_image(i) esystem "wget #{i}" end |
#prepare_these_images(i) ⇒ Object
#
prepare_these_images
#
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/cyberweb/utility_scripts/copy_all_images_from_this_webpage_to_the_current_working_directory.rb', line 67 def prepare_these_images(i) opne "Operating on #{steelblue(i.size.to_s)} images next." i.each {|entry| if entry.start_with?('http') and !File.exist?(File.basename(entry)) download_this_image(entry) elsif entry.start_with?('../') or File.file?(entry) # Then it must be a local image file. # =================================================================== # # So, first we must find out the full path # =================================================================== # if entry.start_with?('../') target = RELATIVE_IMAGE_DIRECTORY+ # IMAGE_DIRECTORY entry.delete_prefix('../' * entry.scan(/\.\.\//).size) else target = entry.dup end unless File.exist? File.basename(target) opne rev+'Working on the following local image next: '+ steelblue(target) copy_this_image(target) end else puts 'Unhandled '+entry+'.' unless File.exist?(File.basename(entry)) end } end |
#reset ⇒ Object
#
reset (reset tag)
#
52 53 54 55 |
# File 'lib/cyberweb/utility_scripts/copy_all_images_from_this_webpage_to_the_current_working_directory.rb', line 52 def reset super() infer_the_namespace end |
#run ⇒ Object
#
run (run tag)
#
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/cyberweb/utility_scripts/copy_all_images_from_this_webpage_to_the_current_working_directory.rb', line 103 def run _ = first_argument? if _ and File.exist?(_) opne "#{rev}Working on the file #{sfile(_)} #{rev}next." dataset = default_read(_) # ===================================================================== # # Determine the regex to use: # ===================================================================== # use_this_regex = /<img(.+)src="(.*?)"(.*)>/ # See: https://rubular.com/r/19LkHDFjX9Hg5o all_images = dataset.scan(use_this_regex).map {|array| array[1] } # ===================================================================== # # Now we should have all images that need to be prepared. So, we can # next pass these images into a separate method that will download # these images for us. # ===================================================================== # prepare_these_images(all_images) end end |