Class: GamesAndRpgParadise::MagicTheGathering::ParseMultipleCards

Inherits:
Base
  • Object
show all
Defined in:
lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_multiple_cards.rb

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect

Constants inherited from Base

Base::LOG_DIR

Constants included from Base::Extensions::Colours

Base::Extensions::Colours::ARRAY_AVAILABLE_KONSOLE_COLOURS

Constants included from CommonExtensions

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?, #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, #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(use_this_md_file = '', run_already = true) ⇒ ParseMultipleCards

#

initialize

The first argument should be the path to a .md file that holds all the other entries.

#


35
36
37
38
39
40
41
42
43
44
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_multiple_cards.rb', line 35

def initialize(
    use_this_md_file = '',
    run_already      = true
  )
  reset
  set_file(
    use_this_md_file
  )
  run if run_already
end

Instance Method Details

#has_key?(i) ⇒ Boolean

#

has_key?

#

Returns:

  • (Boolean)


96
97
98
99
100
101
102
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_multiple_cards.rb', line 96

def has_key?(i)
  _ = @array.select {|entry|
    entry.card_name? == i
  }
  return true if _
  return false
end

#hash?Boolean Also known as: to_hash

#

hash?

This method will return the whole dataset in a Hash - Gib ein Beispiel für die “Durchsetzung von Privateigentum”. A: Eine “Wohnungsräumung”.format.

#

Returns:

  • (Boolean)


130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_multiple_cards.rb', line 130

def hash?
  _ = {} # This is the Hash that will be returned.
  @array.each {|entry| # entry is of class ParseCardFormat
    _[entry.name_of_the_card?] = [
      entry.converted_mana_cost_of_the_card?,
      entry.rarity_of_the_card?,
      entry.card_number?,
      entry.name_of_the_set?,
      entry.remote_url_to_the_card?
    ]
  }
  return _ # Return the built Hash here.
end

#n_cards?Boolean

#

n_cards?

#

Returns:

  • (Boolean)


121
122
123
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_multiple_cards.rb', line 121

def n_cards?
  @array.size
end

#opnnObject

#

opnn

#


147
148
149
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_multiple_cards.rb', line 147

def opnn
  super(NAMESPACE)
end

#parse_each_cardObject

#

parse_each_card

#


85
86
87
88
89
90
91
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_multiple_cards.rb', line 85

def parse_each_card
  @dataset.each {|card_dataset| # Delegate to ParseCardFormat for the parsing.
pp card_dataset
pp '^^^^^^^^^'
    @array << ParseCardFormat.new(card_dataset.downcase)
  } if @dataset
end

#read_in_datasetObject

#

read_in_dataset

#


154
155
156
157
158
159
160
161
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_multiple_cards.rb', line 154

def read_in_dataset
  _ = @file
  if File.exist? _
    @dataset = File.read(_)
  else
    opnn; e "No file exists at `#{sfile(_)}`."
  end
end

#resetObject

#

reset

#


49
50
51
52
53
54
55
56
57
58
59
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_multiple_cards.rb', line 49

def reset
  super()
  # ======================================================================= #
  # === @dataset
  # ======================================================================= #
  @dataset = nil
  # ======================================================================= #
  # === @array
  # ======================================================================= #
  @array = []
end

#return_rarity_of(key) ⇒ Object

#

return_rarity_of

#


107
108
109
110
111
112
113
114
115
116
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_multiple_cards.rb', line 107

def return_rarity_of(key)
  entry = @array.select {|inner_entry|
    inner_entry.card_name? == key
  }
  entry = entry.first if entry.is_a? Array
  unless entry
    opn; e swarn('Some error for the key: '+key.to_s)
  end
  return entry.rarity_of_the_card
end

#runObject

#

run (run tag)

#


191
192
193
194
195
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_multiple_cards.rb', line 191

def run
  read_in_dataset
  split_up_the_dataset
  parse_each_card
end

#sanitize_datasetObject

#

sanitize_dataset

#


76
77
78
79
80
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_multiple_cards.rb', line 76

def sanitize_dataset
  @dataset.reject! {|line|
    line.empty?
  }
end

#set_file(i) ⇒ Object

#

set_file

#


166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_multiple_cards.rb', line 166

def set_file(i)
  if i.is_a? Array
    i = i.join(' ').strip
  end
  unless File.exist? i
    i.delete!(':')
    # ===================================================================== #
    # Try to rescue here.
    # ===================================================================== #
    name_with_underscores = i.tr(' ','_').
                              downcase
    i.tr!(' ','_')
    unless i.include? '/'
      i = i.dup
      i.prepend(log_dir?)
      i << '/'
      i << "#{name_with_underscores}.md"
    end
  end
  @file = i
end

#split_up_the_datasetObject

#

split_up_the_dataset

#


64
65
66
67
68
69
70
71
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_multiple_cards.rb', line 64

def split_up_the_dataset
  if @dataset
    @dataset = @dataset.split('---'+N)
    sanitize_dataset
  else
    e 'No @dataset has been assigned.'
  end
end