Sha256: 9e40c7bf08a33850d2730491a78ff5abfb1b6debd712571c00bc5125a938c991

Contents?: true

Size: 1.17 KB

Versions: 8

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

require_relative '../../lib/LittleWeasel/modules/locale'

module Support
  # This module contains methods to help with dictionary files.

  class Locale
    include LittleWeasel::Modules::Locale

    attr_accessor :language, :region

    def initialize(language:, region:)
      self.language = language
      self.region = region
    end
  end

  module FileHelpers
    module_function

    def locale_for(language:, region: nil)
      Locale.new(language: language, region: region).locale
    end

    def region_dictionary_path(language:, region:)
      file_name = locale_for language: language, region: region
      dictionary_path_for file_name: file_name
    end

    def language_dictionary_path(language:)
      file_name = locale_for language: language
      dictionary_path_for file_name: file_name
    end

    # :reek:UtilityFunction - ignored, this is only for specs.
    def dictionary_path_for(locale: nil, file_name: nil)
      file_name ||= locale
      File.join(File.dirname(__FILE__), "files/#{file_name}.txt")
    end

    def dictionary_words_for(dictionary_file_path:)
      File.read(dictionary_file_path, mode: 'r')&.split
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
LittleWeasel-5.0.13 spec/support/file_helpers.rb
LittleWeasel-5.0.12 spec/support/file_helpers.rb
LittleWeasel-5.0.11 spec/support/file_helpers.rb
LittleWeasel-5.0.10 spec/support/file_helpers.rb
LittleWeasel-5.0.9 spec/support/file_helpers.rb
LittleWeasel-5.0.8 spec/support/file_helpers.rb
LittleWeasel-5.0.7 spec/support/file_helpers.rb
LittleWeasel-5.0.6 spec/support/file_helpers.rb