Class: LittleWeasel::DictionaryKey

Inherits:
Object
  • Object
show all
Includes:
Modules::LanguageValidatable, Modules::Locale, Modules::RegionValidatable, Modules::Taggable
Defined in:
lib/LittleWeasel/dictionary_key.rb

Overview

This class describes a unique key associated with a particular dictionary file. Dictionary keys are used to identify a dictionary on which an action should be performed.

Instance Attribute Summary collapse

Attributes included from Modules::Taggable

#tag

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Modules::Taggable

#tagged?

Methods included from Modules::TagValidatable

#validate_tag, validate_tag

Methods included from Modules::RegionValidatable

#validate_region, validate_region

Methods included from Modules::Locale

#locale

Methods included from Modules::Region

#normalize_region, normalize_region, #normalize_region!, #region?

Methods included from Modules::Language

#language?, #normalize_language, normalize_language, #normalize_language!

Methods included from Modules::LanguageValidatable

#validate_language, validate_language

Constructor Details

#initialize(language:, region: nil, tag: nil) ⇒ DictionaryKey

Returns a new instance of DictionaryKey.



20
21
22
23
24
25
26
27
28
29
# File 'lib/LittleWeasel/dictionary_key.rb', line 20

def initialize(language:, region: nil, tag: nil)
  validate_language language: language
  self.language = normalize_language language

  validate_region region: region
  self.region = normalize_region region

  validate_tag tag: tag
  self.tag = tag
end

Instance Attribute Details

#languageObject

Returns the value of attribute language.



18
19
20
# File 'lib/LittleWeasel/dictionary_key.rb', line 18

def language
  @language
end

#regionObject

Returns the value of attribute region.



18
19
20
# File 'lib/LittleWeasel/dictionary_key.rb', line 18

def region
  @region
end

Class Method Details

.key(language:, region: nil, tag: nil) ⇒ Object



39
40
41
# File 'lib/LittleWeasel/dictionary_key.rb', line 39

def key(language:, region: nil, tag: nil)
  new(language: language, region: region, tag: tag).key
end

Instance Method Details

#keyObject



31
32
33
34
35
# File 'lib/LittleWeasel/dictionary_key.rb', line 31

def key
  return locale unless tagged?

  "#{locale}-#{tag}"
end

#to_sObject



36
37
38
39
40
# File 'lib/LittleWeasel/dictionary_key.rb', line 36

def key
  return locale unless tagged?

  "#{locale}-#{tag}"
end