module TyranoDsl::ParsingWords::ParsingWordsModule

Protected Instance Methods

check_character_exist(character_name, character_stance = nil) click to toggle source

@param [String] character_name @param [String, nil] character_stance @return [void] @raise [TyranoDsl::TyranoException]

# File lib/tyrano_dsl/parsing_words/parsing_words_module.rb, line 35
def check_character_exist(character_name, character_stance = nil)
  character = context.world.characters[character_name]
  unless character
    raise_unknown('character', character_name, context.world.characters.keys)
  end
  if character_stance && !character.stances.key?(character_stance)
    raise_unknown('stance', character_stance, character.stances.keys)
  end
end
check_variable_exist(variable_name) click to toggle source

@param [String] variable_name @return [void] @raise [TyranoDsl::TyranoException]

# File lib/tyrano_dsl/parsing_words/parsing_words_module.rb, line 25
def check_variable_exist(variable_name)
  unless context.world.variables.key?(variable_name)
    raise_unknown('variable', variable_name, context.world.variables.keys)
  end
end
file_full_path(file_path) click to toggle source

@param [String] file_path @return [String] @raise [TyranoDsl::TyranoException]

# File lib/tyrano_dsl/parsing_words/parsing_words_module.rb, line 14
def file_full_path(file_path)
  absolute_path = File.absolute_path(file_path, File.dirname(included_files_hierarchy.last))
  unless File.exist?(absolute_path)
    raise TyranoDsl::TyranoException, "Missing file [#{absolute_path}]"
  end
  absolute_path
end
raise_unknown(type, unknown_name, current_elements) click to toggle source

@param [String] type @param [String] unknown_name @param [Array<String>] current_elements @return [void] @raise [TyranoDsl::TyranoException]

# File lib/tyrano_dsl/parsing_words/parsing_words_module.rb, line 66
def raise_unknown(type, unknown_name, current_elements)
  raise TyranoDsl::TyranoException, "Unknown #{type} [#{unknown_name}], currently #{current_elements.length} defined: #{current_elements.sort.collect {|e| "[#{e}]"}.join(', ')}"
end
symbolize(string) click to toggle source

@param [String] string @return [Symbol]

# File lib/tyrano_dsl/parsing_words/parsing_words_module.rb, line 57
def symbolize(string)
  string.to_sym rescue string
end
symbolize_keys(hash) click to toggle source

@param [Hash] hash @return [Hash{Symbol=>Object}]

# File lib/tyrano_dsl/parsing_words/parsing_words_module.rb, line 47
def symbolize_keys(hash)
  result = {}
  hash.keys.each do |key|
    result[symbolize(key)] = hash[key]
  end
  result
end