Class: GamesAndRpgParadise::MagicTheGathering::DownloadSingleCard
- Defined in:
- lib/games_and_rpg_paradise/games/magic_the_gathering/classes/download_single_card.rb
Overview
GamesAndRpgParadise::MagicTheGathering::DownloadSingleCard
Constant Summary collapse
- DEFAUT_REMOTE_URL =
#
DEFAUT_REMOTE_URL
#
'https://gatherer.wizards.com/Pages/Card/Details.aspx?name=Slayer%27s+Plate'
Constants inherited from Base
Constants included from Base::Extensions::Colours
Base::Extensions::Colours::ARRAY_AVAILABLE_KONSOLE_COLOURS
Constants included from CommonExtensions
CommonExtensions::CONTROL_C_CODE, CommonExtensions::N
Class Method Summary collapse
-
.[](remote_url = '') ⇒ Object
# === GamesAndRpgParadise::MagicTheGathering::DownloadSingleCard[] ========================================================================= #.
Instance Method Summary collapse
-
#initialize(remote_url = DEFAULT_REMOTE_URL, run_already = true) ⇒ DownloadSingleCard
constructor
# === initialize ========================================================================= #.
-
#remote_url? ⇒ Boolean
# === remote_url? ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#set_remote_url(i = DEFAUT_REMOTE_URL) ⇒ Object
# === set_remote_url ========================================================================= #.
Methods inherited from Base
#convert, #ensure_that_the_log_directory_exists, #esystem, #is_png_file?, #lightgreen, #log_dir?, #opnn, #orange, #palegoldenrod, #pngopt, #rev, #slateblue, #springgreen, #turquoise, #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
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
Constructor Details
#initialize(remote_url = DEFAULT_REMOTE_URL, run_already = true) ⇒ DownloadSingleCard
#
initialize
#
28 29 30 31 32 33 34 35 |
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/download_single_card.rb', line 28 def initialize( remote_url = DEFAULT_REMOTE_URL, run_already = true ) reset set_remote_url(remote_url) run if run_already end |
Class Method Details
.[](remote_url = '') ⇒ Object
#
GamesAndRpgParadise::MagicTheGathering::DownloadSingleCard[]
#
98 99 100 |
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/download_single_card.rb', line 98 def self.[](remote_url = '') new(remote_url) end |
Instance Method Details
#remote_url? ⇒ Boolean
#
remote_url?
#
57 58 59 |
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/download_single_card.rb', line 57 def remote_url? @remote_url end |
#reset ⇒ Object
#
reset (reset tag)
#
40 41 42 |
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/download_single_card.rb', line 40 def reset super() end |
#run ⇒ Object
#
run (run tag)
#
64 65 66 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 92 93 |
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/download_single_card.rb', line 64 def run e "We will read from the URL #{sfancy(@remote_url)} next." @dataset = open(@remote_url).read # ======================================================================= # # First, we need to find the multiverseid entry. # ======================================================================= # @dataset =~ REGEX_MULTIVERSEID # This is the same as REGEX_FOR_FINDING_A_CARD the_id = $1.to_s.dup name_of_the_card = $2.to_s.dup card_url = GATHERER_WIZARDS_COM+ 'Handlers/Image.ashx?multiverseid='+ the_id.to_s+ '&type=card' # ======================================================================= # # Next, use File.binwrite. The first argument is the name of # the card. The second is the read remote_url. # ======================================================================= # _ = "#{name_of_the_card.tr(' ','_')}.jpg" e "#{rev}Now writing into #{sfile(_)}." File.binwrite(_, open(card_url).read) # ======================================================================= # # Convert fake .jpg into .png files. # ======================================================================= # if is_png_file? _ e 'Renaming to .png as it is a .png file.' new_filename = _.gsub(/\.png$/,'')+'.jpg' mv(_, new_filename) _ = new_filename end end |
#set_remote_url(i = DEFAUT_REMOTE_URL) ⇒ Object
#
set_remote_url
#
47 48 49 50 51 52 |
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/download_single_card.rb', line 47 def set_remote_url(i = DEFAUT_REMOTE_URL) i = i.first if i.is_a? Array i = DEFAUT_REMOTE_URL if i.nil? i = i.to_s.dup @remote_url = i end |