class TicTacToeRZ::Languages::LanguageOptionsAdapter

Constants

DEFAULT_LANGUAGE_TAG
GLOBAL_SETTINGS_FILE

Attributes

directory[R]
language[R]

Public Class Methods

new(directory_path) click to toggle source
# File lib/tic_tac_toe_rz/tictactoeruby.core/languages/language_options_adapter.rb, line 16
def initialize(directory_path)
  @directory = directory_path
  tag = stored_default_tag
  tag = DEFAULT_LANGUAGE_TAG if !valid?(tag)
  @language = Language.new(tag)
end

Public Instance Methods

all_languages() click to toggle source
# File lib/tic_tac_toe_rz/tictactoeruby.core/languages/language_options_adapter.rb, line 46
def all_languages
  file_path = @directory + "language_options." + default_language_tag + ".yaml"
  YAMLReader.read_data(file_path, "languages")
end
default_language_tag() click to toggle source
# File lib/tic_tac_toe_rz/tictactoeruby.core/languages/language_options_adapter.rb, line 23
def default_language_tag
  result = @language.tag.to_s
end
default_language_tag!(tag) click to toggle source
# File lib/tic_tac_toe_rz/tictactoeruby.core/languages/language_options_adapter.rb, line 38
def default_language_tag!(tag)
  dir = Dir.pwd
  location = File.dirname(__FILE__)
  raise Exceptions::InvalidValueError, "tag = #{tag}, directory = #{@directory}, working dir = #{dir}, location = #{location}" if !valid?(tag)
  YAMLWriter.write_data(@directory + GLOBAL_SETTINGS_FILE, "selected_language_tag", tag)
  @language.tag = tag
end
input_choices() click to toggle source
# File lib/tic_tac_toe_rz/tictactoeruby.core/languages/language_options_adapter.rb, line 60
def input_choices
  options = all_languages
  count = options.size
  valid_selections = [*1..count]
  valid_selections = valid_selections.map(&:to_s)
end
language_descriptions() click to toggle source
# File lib/tic_tac_toe_rz/tictactoeruby.core/languages/language_options_adapter.rb, line 51
def language_descriptions
  options = all_languages
  languages = []
  options.each do |language|
    languages << language['description']
  end
  result = languages
end
language_tag_for_description(language) click to toggle source
# File lib/tic_tac_toe_rz/tictactoeruby.core/languages/language_options_adapter.rb, line 82
def language_tag_for_description(language)
  options = all_languages
  result = options.find{|languages| languages["description"] == language}
  tag = result["tag"]
  return tag
end
language_tag_for_input_choice(input_choice) click to toggle source
# File lib/tic_tac_toe_rz/tictactoeruby.core/languages/language_options_adapter.rb, line 76
def language_tag_for_input_choice(input_choice)
  input = input_choice.to_i
  options = all_languages
  tag = options[input - 1]['tag']
end
language_tags() click to toggle source
# File lib/tic_tac_toe_rz/tictactoeruby.core/languages/language_options_adapter.rb, line 67
def language_tags
  options = all_languages
  tags = []
  options.each do |language|
    tags << language['tag']
  end
  result = tags
end
stored_default_tag() click to toggle source
# File lib/tic_tac_toe_rz/tictactoeruby.core/languages/language_options_adapter.rb, line 27
def stored_default_tag
  path = @directory + GLOBAL_SETTINGS_FILE
  YAMLReader.read_data(path, "selected_language_tag")
end
valid?(tag) click to toggle source
# File lib/tic_tac_toe_rz/tictactoeruby.core/languages/language_options_adapter.rb, line 32
def valid?(tag)
  file_path = @directory + "language_options." + tag + ".yaml"
  file_path = File.dirname(__FILE__) + '/' + file_path
  File.exist?(file_path)
end