Class: WorldDb::UsageReader

Inherits:
BaseReader show all
Defined in:
lib/worlddb/readers/usage.rb

Instance Attribute Summary

Attributes inherited from BaseReader

#include_path

Instance Method Summary collapse

Methods inherited from BaseReader

#initialize, #skip_tags?, #strict?

Constructor Details

This class inherits a constructor from WorldDb::BaseReader

Instance Method Details

#read(name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/worlddb/readers/usage.rb', line 7

def read( name )
  reader = HashReaderV2.new( name, include_path )

  reader.each do |key, value|
    
    ### fix:
    ##  move to Usage.read() for (re)use

    logger.debug "   adding langs >>#{value}<<to country >>#{key}<<"
    
    country = Country.find_by_key!( key )
    
    lang_keys = value.split(',')
    lang_keys.each do |lang_key|

      ### remove (optional comment) from key (e.g. carribean (islands))
      lang_key = lang_key.gsub( /\(.+\)/, '' )
      ## remove leading n trailing space
      lang_key = lang_key.strip

      lang = Lang.find_by_key!( lang_key )
      Usage.create!( country_id: country.id, lang_id: lang.id, official: true, minor: false )
    end
  end
end