Class: GamesAndRpgParadise::MagicTheGathering::ParseCardFormat

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

Overview

GamesAndRpgParadise::MagicTheGathering::ParseCardFormat

Constant Summary collapse

DEFAULT_TEST_STRING =
#

DEFAULT_TEST_STRING

This string can be used to test the custom format we will be using for the cards.

#
'
  
---
Kird Ape
Common
/home/Temp/Magic_the_gathering/Eternal_Masters/Kird_Ape.jpg
Red
137
---'

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?, #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(i = DEFAULT_TEST_STRING, run_already = true) ⇒ ParseCardFormat

#

initialize

#


40
41
42
43
44
45
46
47
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_card_format.rb', line 40

def initialize(
    i           = DEFAULT_TEST_STRING,
    run_already = true
  )
  reset
  parse_this_string(i)
  run if run_already
end

Instance Method Details

#assign_proper_entriesObject

#

assign_proper_entries

This method will assign the proper entries.

#


112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_card_format.rb', line 112

def assign_proper_entries
  _ = dataset?
  # ======================================================================= #
  # Next, we assign each entry to the specific instance variable.
  # ======================================================================= #
  @name_of_the_card       = _[0] # Position 1
  @rarity_of_the_card     = _[1] # Position 2
  @local_path_to_the_card = _[2] # Position 3
  @card_colour            = _[3] # Position 3
  @card_number            = _[4] # Position 4
  @remote_url_to_the_card = _[5] # Last position 6 - remote URL to the card.
  if @local_path_to_the_card and @name_of_the_card_set.empty?
    @name_of_the_card_set = determine_card_set_from(@local_path_to_the_card)
  end
end

#card_number?Boolean

#

card_number?

#

Returns:

  • (Boolean)


138
139
140
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_card_format.rb', line 138

def card_number?
  @card_number
end

#converted_mana_cost_of_the_card?Boolean

#

converted_mana_cost_of_the_card?

#

Returns:

  • (Boolean)


145
146
147
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_card_format.rb', line 145

def converted_mana_cost_of_the_card?
  0 # This is 0 for now. If we ever need this differently, we will change it.
end

#dataset?Boolean

#

dataset?

#

Returns:

  • (Boolean)


103
104
105
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_card_format.rb', line 103

def dataset?
  @dataset
end

#determine_card_set_from(i) ⇒ Object

#

determine_card_set_from

#


168
169
170
171
172
173
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_card_format.rb', line 168

def determine_card_set_from(i)
  if i.end_with?('.jpg') and i.count('/') > 2
    i = i.split('/')[4] # Input is like: '/Depot/Temp/magic_the_gathering/Kaladesh/Aether_Meltdown.jpg'
  end
  return i
end

#local_path?Boolean Also known as: url?

#

local_path?

#

Returns:

  • (Boolean)


161
162
163
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_card_format.rb', line 161

def local_path?
  @local_path
end

#name_of_the_card?Boolean Also known as: name?, card_name?

#

name_of_the_card?

#

Returns:

  • (Boolean)


178
179
180
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_card_format.rb', line 178

def name_of_the_card?
  @name_of_the_card
end

#name_of_the_set?Boolean

#

name_of_the_set?

#

Returns:

  • (Boolean)


131
132
133
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_card_format.rb', line 131

def name_of_the_set?
  @name_of_the_card_set
end

#parse_this_string(i) ⇒ Object

#

parse_this_string

#


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_card_format.rb', line 75

def parse_this_string(i)
  i = DEFAULT_TEST_STRING if i.nil?
  if i.is_a? Array
    if i.empty?
      i << DEFAULT_TEST_STRING
    end
    i = i.join
  end
  if i.is_a? String and i.frozen?
    i = i.dup
  end
  i.lstrip! # We don't need leading strings.
  i.delete!('-') if i.include? '---'
  i = i.split(N) # We need an Array again.
  i.reject! {|entry| entry.strip.empty? }
  set_dataset(i) # Assign this sanitized dataset.
end

#purge_dataset_variableObject

#

purge_dataset_variable

Get rid of the @dataset variable again.

#


154
155
156
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_card_format.rb', line 154

def purge_dataset_variable
  remove_instance_variable(:@dataset)
end

#rarity_of_the_card?Boolean Also known as: return_rarity, rarity_of_the_card

#

rarity_of_the_card?

#

Returns:

  • (Boolean)


186
187
188
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_card_format.rb', line 186

def rarity_of_the_card?
  @rarity_of_the_card
end

#remote_url_to_the_card?Boolean Also known as: remote_url_to_the_card

#

remote_url_to_the_card?

#

Returns:

  • (Boolean)


194
195
196
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_card_format.rb', line 194

def remote_url_to_the_card?
  @remote_url_to_the_card.to_s
end

#resetObject

#

reset

#


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_card_format.rb', line 52

def reset
  super()
  # ======================================================================= #
  # === @name_of_the_card_set
  # ======================================================================= #
  @name_of_the_card_set   = '' # This variable will store the name of the card set.
  # ======================================================================= #
  # === @name_of_the_card
  # ======================================================================= #
  @name_of_the_card       = nil
  # ======================================================================= #
  # === @rarity_of_the_card
  # ======================================================================= #
  @rarity_of_the_card     = nil
  @local_path_to_the_card = nil
  @card_number            = nil
  @card_colour            = nil
  @remote_url_to_the_card = nil
end

#runObject

#

run

#


201
202
203
204
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_card_format.rb', line 201

def run
  assign_proper_entries
  purge_dataset_variable
end

#set_dataset(i) ⇒ Object

#

set_dataset

#


96
97
98
# File 'lib/games_and_rpg_paradise/games/magic_the_gathering/classes/parse_card_format.rb', line 96

def set_dataset(i)
  @dataset = i
end