Class: EhbrsRubyUtils::Vg::Wii::GameFile

Inherits:
Pathname
  • Object
show all
Defined in:
lib/ehbrs_ruby_utils/vg/wii/game_file.rb

Constant Summary collapse

DISC_NUMBER_PATTERN =
/disc.?(\d)/i.freeze
FORMAT =
::EacRubyUtils::CustomFormat.new(
  b: :basename,
  d: :dirname,
  D: :disc_number,
  e: :extname,
  i: :id6,
  m: :normalized_disc_name,
  n: :disc_name,
  N: :nintendont_basename,
  s: :sanitized_disc_name,
  t: :database_title,
  T: :disc_type
)

Instance Method Summary collapse

Instance Method Details

#database_titleObject



32
33
34
# File 'lib/ehbrs_ruby_utils/vg/wii/game_file.rb', line 32

def database_title
  properties.fetch('DB title')
end

#disc_nameObject



36
37
38
# File 'lib/ehbrs_ruby_utils/vg/wii/game_file.rb', line 36

def disc_name
  properties.fetch('Disc name')
end

#disc_numberObject



40
41
42
# File 'lib/ehbrs_ruby_utils/vg/wii/game_file.rb', line 40

def disc_number
  DISC_NUMBER_PATTERN.if_match(basename.to_s, false) { |m| m[1].to_i }.if_present(1)
end

#disc_typeObject



44
45
46
# File 'lib/ehbrs_ruby_utils/vg/wii/game_file.rb', line 44

def disc_type
  properties.fetch('File & disc type/type')
end

#format(string) ⇒ Object



48
49
50
# File 'lib/ehbrs_ruby_utils/vg/wii/game_file.rb', line 48

def format(string)
  FORMAT.format(string).with(self)
end

#id6Object



61
62
63
# File 'lib/ehbrs_ruby_utils/vg/wii/game_file.rb', line 61

def id6
  properties.fetch('Disc & part IDs/disc')
end

#nintendont_basenameObject



56
57
58
59
# File 'lib/ehbrs_ruby_utils/vg/wii/game_file.rb', line 56

def nintendont_basename
  n = disc_number
  n == 1 ? 'game' : "disc#{n}"
end

#normalized_disc_nameObject



52
53
54
# File 'lib/ehbrs_ruby_utils/vg/wii/game_file.rb', line 52

def normalized_disc_name
  sanitized_disc_name.downcase
end

#sanitized_disc_nameObject



65
66
67
# File 'lib/ehbrs_ruby_utils/vg/wii/game_file.rb', line 65

def sanitized_disc_name
  ::ActiveSupport::Inflector.transliterate(disc_name).gsub(/[^0-9a-z ]/i, '')
end

#valid?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/ehbrs_ruby_utils/vg/wii/game_file.rb', line 69

def valid?
  properties.present?
end

#wit_pathObject



73
74
75
# File 'lib/ehbrs_ruby_utils/vg/wii/game_file.rb', line 73

def wit_path
  ::EhbrsRubyUtils::Vg::Wii::Wit::Path.new(disc_type, self)
end