Class: GamesAndRpgParadise::MagicTheGathering::ShowPriceInformationFromMagickartenmarkt
- Inherits:
-
Base
- Object
- Base
- Base
- GamesAndRpgParadise::MagicTheGathering::ShowPriceInformationFromMagickartenmarkt
show all
- Defined in:
- lib/games_and_rpg_paradise/games/magic_the_gathering/classes/show_price_information_from_magickartenmarkt.rb
Overview
Constant Summary
collapse
- USE_THIS_AS_INPUT_FILE =
FILE_KARTENLISTE_CSV
- FILTER_FOR_N_ENTRIES =
#
FILTER_FOR_N_ENTRIES
This can be nil or a number. If nil, we will not apply any filter.
If a number is used, then we will use that number to select only n entries from our dataset.
#
50
- BR =
'<br>'
Constants inherited
from Base
Base::LOG_DIR
Base::Extensions::Colours::ARRAY_AVAILABLE_KONSOLE_COLOURS
CommonExtensions::CONTROL_C_CODE, CommonExtensions::N
Class Method Summary
collapse
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
64
65
66
67
68
69
70
71
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/show_price_information_from_magickartenmarkt.rb', line 64
def initialize(
i = nil,
run_already = true
)
reset
set_input(i)
run if run_already
end
|
Class Method Details
.[](i = ARGV) ⇒ Object
285
286
287
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/show_price_information_from_magickartenmarkt.rb', line 285
def self.[](i = ARGV)
new(i)
end
|
.show_path_to_main_file ⇒ Object
#
GamesAndRpgParadise::MagicTheGathering::ShowPriceInformationFromMagickartenmarkt.show_path_to_main_file
#
292
293
294
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/show_price_information_from_magickartenmarkt.rb', line 292
def self.show_path_to_main_file
puts USE_THIS_AS_INPUT_FILE
end
|
Instance Method Details
#create_html_page ⇒ Object
#
create_html_page (html tag)
#
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/show_price_information_from_magickartenmarkt.rb', line 150
def create_html_page
_ = ''.dup
_ << '<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Price Information from magickartenmarkt.de</title></head>'+N
_ << '<body>'
counter = 0
total_cost_minimalpreis = 0
@array_dataset.each {|name_of_the_card, name_of_the_set, preistendenz, verfügbar_ab, remote_url|
counter += 1
total_cost_minimalpreis += verfügbar_ab.to_f
_ << BR+'<span style="font-size:1.5em">'+counter.to_s+'</span>'+BR+
'<p style="padding:0.5em; margin:2px">'\
'<b>Name of the card: </b>'+
name_of_the_card+BR+
'<b>Name of the set: </b>'+
name_of_the_set.tr('+',' ')+BR+
'<b>Preistendenz dieser Karte: </b>'+
'<b style="colour:crimson">'+preistendenz.to_s+'</b> '+EURO+BR+
'<b>Verfügbar ab (Minimalpreis): </b>'+
'<b style="colour:crimson">'+verfügbar_ab.to_s+'</b> '+EURO+BR
'</p>'+BR+N
}
_ << BR+'Gesamtkosten (<b>Minimalpreis</b>) dieser '+
@array_dataset.size.to_s+' Karten: <b>'+
total_cost_minimalpreis.to_s+'</b> '+EURO+BR+N
_ << '</body></html>'
into = log_dir?+'price_information_for_my_cards.html'
e 'HTML file created at `'+sfile(into)+'`.'
SaveFile.write_what_into(_, into)
@total_cost_minimalpreis = total_cost_minimalpreis
end
|
104
105
106
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/show_price_information_from_magickartenmarkt.rb', line 104
def input?
@input
end
|
#report_array_dataset(i = @array_dataset) ⇒ Object
#
report_array_dataset
Go through the array-dataset and report it.
#
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/show_price_information_from_magickartenmarkt.rb', line 245
def report_array_dataset(i = @array_dataset)
i.each_with_index {|entry, index|
index += 1
name_of_the_card, name_of_the_set, preistendenz, verfügbar_ab, remote_url = entry
e '('+index.to_s+') The card is: '+
orange(name_of_the_card)+' ('+slateblue(name_of_the_set)+')'
e ' '+palegoldenrod(remote_url)
e ' Preistendenz: '+springgreen(preistendenz.to_s+' Euro')
e ' Verfügbar ab: '+springgreen(verfügbar_ab.to_s+' Euro')
}
end
|
#report_total_costs ⇒ Object
185
186
187
188
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/show_price_information_from_magickartenmarkt.rb', line 185
def report_total_costs
e 'The total cost (Minimalpreis) is: '+
sfancy(@total_cost_minimalpreis.to_s+' Euro')
end
|
#reset ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/show_price_information_from_magickartenmarkt.rb', line 76
def reset
super()
@array_dataset = []
@total_cost_minimalpreis = 0 end
|
#return_default_dataset_as_array(apply_filter_n_entries = FILTER_FOR_N_ENTRIES) ⇒ Object
#
return_default_dataset_as_array
Note that we will get rid of empty lines.
The constant FILTER_FOR_N_ENTRIES is defined at the top of this file and is usually at around 50 entries that will be checked.
#
268
269
270
271
272
273
274
275
276
277
278
279
280
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/show_price_information_from_magickartenmarkt.rb', line 268
def return_default_dataset_as_array(
apply_filter_n_entries = FILTER_FOR_N_ENTRIES
)
_ = input?
_ = FILE_KARTENLISTE_CSV if _.empty? _ = File.readlines(_).reject {|line|
line.start_with?('#') or line.strip.empty?
}
if apply_filter_n_entries
_ = _[0..(apply_filter_n_entries-1)]
end
return _
end
|
#run ⇒ Object
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
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/show_price_information_from_magickartenmarkt.rb', line 111
def run
ensure_that_the_log_directory_exists
array = return_default_dataset_as_array e "We will first sort the main array, consisting of #{array.size.to_s} "\
"entries, before presenting the dataset."
e 'This may take a while so please be patient.'
array.each_with_index {|line, index|
index += 1
print index.to_s+' '
splitted = line.split('|') name_of_the_card, name_of_the_set = splitted
name_of_the_card.strip!
name_of_the_set.strip!
remote_url = ::GamesAndRpgParadise::MagicTheGathering.return_url_for_magickarten_de_for_this_card(
name_of_the_card, name_of_the_set
)
preistendenz = ::GamesAndRpgParadise::MagicTheGathering.return_preistendenz_of_this_card_from_magickartenmarkt(
name_of_the_card, name_of_the_set, :be_quiet
)
verfügbar_ab = ::GamesAndRpgParadise::MagicTheGathering.return_verfügbar_ab_of_this_card_from_magickartenmarkt(
name_of_the_card, name_of_the_set, :be_quiet
)
@array_dataset << [
name_of_the_card, name_of_the_set, preistendenz, verfügbar_ab, remote_url
]
}
sort_dataset report_array_dataset
save_array_dataset
create_html_page
report_total_costs
end
|
#save_array_dataset ⇒ Object
193
194
195
196
197
198
199
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/show_price_information_from_magickartenmarkt.rb', line 193
def save_array_dataset
into = log_dir?+'price_information_for_my_cards.csv'
_ = @array_dataset.map {|line| line.join('|') }
what = _.join(N)
e 'We will also save into `'+sfile(into)+'`.'
SaveFile.write_what_into(what, into)
end
|
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/show_price_information_from_magickartenmarkt.rb', line 216
def set_input(i = USE_THIS_AS_INPUT_FILE)
i = i.first if i.is_a? Array
i = i.to_s.dup
case i
when 'default'
i = USE_THIS_AS_INPUT_FILE
when /help/i
show_help
exit
when /this_csv_file=(.+\.csv)/ i = $1.to_s.dup
end
@input = i
end
|
#show_help ⇒ Object
91
92
93
94
95
96
97
98
99
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/show_price_information_from_magickartenmarkt.rb', line 91
def show_help
e
e 'You can use another .csv file from the commandline.'
e
e 'In order to do this, try a syntax such as the following one:'
e
e ' show_price --this_csv_file=/tmp/foo.csv'
e
end
|
#sort_dataset ⇒ Object
#
sort_dataset (sort tag)
#
204
205
206
207
208
209
210
211
|
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/show_price_information_from_magickartenmarkt.rb', line 204
def sort_dataset
@array_dataset = @array_dataset.sort_by {|name_of_the_card, name_of_the_set, preistendenz, price_available_at, remote_url|
price_available_at.to_f
}.reverse
end
|