Class: Bisu::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/bisu/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash:) ⇒ Config

Returns a new instance of Config.



3
4
5
6
7
8
9
10
11
12
# File 'lib/bisu/config.rb', line 3

def initialize(hash:)
  @hash = hash.deep_symbolize
  @hash.validate_structure!(CONFIG_STRUCT)

  unless dict_struct = DICTIONARY_STRUCT[@hash[:dictionary][:type]]
    raise ArgumentError.new("unknown dictionary type '#{@hash[:dictionary][:type]}'")
  end

  @hash[:dictionary].validate_structure!(dict_struct)
end

Instance Method Details

#dictionaryObject



18
19
20
# File 'lib/bisu/config.rb', line 18

def dictionary
  @hash[:dictionary]
end

#localize_filesObject



26
27
28
29
30
31
32
33
# File 'lib/bisu/config.rb', line 26

def localize_files
  @hash[:translate].each do |t|
    @hash[:languages].each do |l|
      downcase_locale = l[:locale].downcase.gsub("-", "_").gsub(" ", "_")
      yield(t[:in], (t[:"out_#{downcase_locale}"] || t[:out]) % l, l[:locale], l[:language], l[:fallback_language])
    end
  end
end

#to_hObject



14
15
16
# File 'lib/bisu/config.rb', line 14

def to_h
  @hash
end

#typeObject



22
23
24
# File 'lib/bisu/config.rb', line 22

def type
  @hash[:type]
end