Class: GamesAndRpgParadise::MagicTheGathering::ObtainPriceFrom
- Inherits:
-
Base
- Object
- Base
- Base
- GamesAndRpgParadise::MagicTheGathering::ObtainPriceFrom
show all
- Defined in:
- lib/games_and_rpg_paradise/games/magic_the_gathering/classes/obtain_price_from.rb
Overview
Constant Summary
Constants inherited
from Base
Base::LOG_DIR
Base::Extensions::Colours::ARRAY_AVAILABLE_KONSOLE_COLOURS
CommonExtensions::CONTROL_C_CODE, CommonExtensions::N
Instance Method Summary
collapse
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
ecomment, #efancy, #eparse, #forestgreen, #gold, #grey, #lightblue, #mediumseagreen, #mediumslateblue, #peru, #rev, sdir, sfancy, #sfile, simp, #teal, #yellow
#commandline_arguments?, #filter_away_commandline_arguments, #first_argument?, #first_non_hyphened_argument?, #set_commandline_arguments
#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(cmdline_arguments = ARGV, run_already = true) ⇒ ObtainPriceFrom
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/obtain_price_from.rb', line 26
def initialize(
cmdline_arguments = ARGV,
run_already = true
)
reset
set_search_term(
cmdline_arguments
)
run if run_already
end
|
Instance Method Details
#obtain_data_from_this_url(url) ⇒ Object
#
obtain_data_from_this_url
#
101
102
103
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/obtain_price_from.rb', line 101
def obtain_data_from_this_url(url)
URI.open(url).read
end
|
#replace_blanks_with_plus(i) ⇒ Object
#
replace_blanks_with_plus
#
94
95
96
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/obtain_price_from.rb', line 94
def replace_blanks_with_plus(i)
i.tr(' ','+')
end
|
#replace_blanks_with_www_tokens(i) ⇒ Object
#
replace_blanks_with_www_tokens
#
108
109
110
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/obtain_price_from.rb', line 108
def replace_blanks_with_www_tokens(i)
i.gsub(/ /,'%20') end
|
#reset ⇒ Object
40
41
42
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/obtain_price_from.rb', line 40
def reset
super()
end
|
#return_properly_sanitized_search_term ⇒ Object
#
return_properly_sanitized_search_term
#
82
83
84
85
86
87
88
89
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/obtain_price_from.rb', line 82
def return_properly_sanitized_search_term
_ = search_term?.dup
unless _.start_with? 'http'
_.capitalize!
end
_ = replace_blanks_with_plus(_)
return _
end
|
#return_url_for_magickartenmarkt ⇒ Object
#
return_url_for_magickartenmarkt
This should yield the URL to magickartenmarkt.de. However had, some time before October 2020, the URL was changed. It now looks like “www.cardmarket.com/de/Magic/Products/Singles/Fifth-Dawn/Devour-in-Shadow” so we have to respect that. Alternatively, it may look like:
https://www.cardmarket.com/en/Magic/Products/Singles/Revised/Crusade
#
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/obtain_price_from.rb', line 123
def return_url_for_magickartenmarkt
_ = 'https://www.cardmarket.com/de/Magic/Products/Singles/Fifth-Dawn/'.dup
consider_to_add_this = return_properly_sanitized_search_term
if consider_to_add_this.start_with? 'http'
_ = consider_to_add_this
else
_ << consider_to_add_this
end
return _
end
|
#return_url_for_mtgprice ⇒ Object
#
return_url_for_mtgprice
This URL can be used for mtgprice.com
#
74
75
76
77
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/obtain_price_from.rb', line 74
def return_url_for_mtgprice
URL_MTGPRICE+'?search='+
return_properly_sanitized_search_term end
|
#run ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/obtain_price_from.rb', line 142
def run
_ = url?
opn; e "Working on the following remote URL next:"
e
e " #{simp(_)}"
e
dataset = obtain_data_from_this_url(_)
puts dataset
what = dataset
into = '/Depot/j/foobar.md'
e into
::SaveFile.write_what_into(what, into)
regex_to_use =
/Preis-Trend<\/dt><dd class="col-6 col-xl-7"><span>(\d{1,2},\d{1,2}) €<\/span><\/dd>/
dataset =~ regex_to_use
match = $1.to_s.dup
e 'Preistendenz für die Karte `'+
simp(sterm?)+'`: '+
orange(match.to_s+' €')
end
|
#search_term? ⇒ Boolean
Also known as:
sterm?
57
58
59
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/obtain_price_from.rb', line 57
def search_term?
@search_term
end
|
#set_search_term(i = ARGV) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/obtain_price_from.rb', line 47
def set_search_term(i = ARGV)
if i.is_a? Array
i = i.join(' ').strip
end
@search_term = i.dup
end
|
#url? ⇒ Boolean
64
65
66
67
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/obtain_price_from.rb', line 64
def url?
return_url_for_magickartenmarkt
end
|