Class: LangFactory
- Inherits:
-
Object
- Object
- LangFactory
- Includes:
- Singleton
- Defined in:
- lib/asker/lang/lang_factory.rb
Overview
-
Read all language codes defined into configuration file
-
and load every language
Lang objects are reused
Instance Method Summary collapse
- #default ⇒ Object
-
#get(code) ⇒ Object
Return Lang object associated to code.
-
#initialize ⇒ LangFactory
constructor
A new instance of LangFactory.
Constructor Details
#initialize ⇒ LangFactory
Returns a new instance of LangFactory.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/asker/lang/lang_factory.rb', line 15 def initialize # Read all language codes from configuration file and load every language @default = Application.instance.config["languages"]["default"].downcase @langs = {} Application.instance.config["languages"].each_pair do |key, value| code = key.downcase next if code == "default" @langs[code] = Lang.new(code) if value.downcase == "yes" end end |
Instance Method Details
#default ⇒ Object
40 41 42 |
# File 'lib/asker/lang/lang_factory.rb', line 40 def default get(@default) end |
#get(code) ⇒ Object
Return Lang object associated to code
30 31 32 33 34 35 36 37 38 |
# File 'lib/asker/lang/lang_factory.rb', line 30 def get(code) return @langs[code] unless @langs[code].nil? Logger.error "LangFactory: Unknown Lang with [code=#{code}]" Logger.error " (a) Revise input file code lang" Logger.error " (b) Revise asker.ini configuration" Logger.error " (c) Revise template files" exit 1 end |