Class: TwitterCldr::Resources::Importer

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_cldr/resources/importer.rb

Constant Summary collapse

DEFAULT_ENGINE =
:mri

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Importer

Returns a new instance of Importer.



67
68
69
70
# File 'lib/twitter_cldr/resources/importer.rb', line 67

def initialize(options = {})
  @params = self.class.default_params.merge(options)
  @requirements = self.class.requirements
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



65
66
67
# File 'lib/twitter_cldr/resources/importer.rb', line 65

def params
  @params
end

#requirementsObject (readonly)

Returns the value of attribute requirements.



65
66
67
# File 'lib/twitter_cldr/resources/importer.rb', line 65

def requirements
  @requirements
end

Class Method Details

.default_paramsObject



38
39
40
41
42
43
44
# File 'lib/twitter_cldr/resources/importer.rb', line 38

def default_params
  parameters.merge(
    output_path: @output_path,
    locales: get_locales,
    ruby_engine: @ruby_engine || DEFAULT_ENGINE
  )
end

.locales(locs) ⇒ Object



30
31
32
# File 'lib/twitter_cldr/resources/importer.rb', line 30

def locales(locs)
  @locales = locs
end

.output_path(path) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/twitter_cldr/resources/importer.rb', line 22

def output_path(path)
  @output_path = if path.start_with?('/')
    path
  else
    File.join(TwitterCldr::RESOURCES_DIR, path)
  end
end

.parameter(key, value) ⇒ Object



34
35
36
# File 'lib/twitter_cldr/resources/importer.rb', line 34

def parameter(key, value)
  parameters[key] = value
end

.parametersObject



50
51
52
# File 'lib/twitter_cldr/resources/importer.rb', line 50

def parameters
  @parameters ||= {}
end

.requirement(name, *args) ⇒ Object



13
14
15
16
# File 'lib/twitter_cldr/resources/importer.rb', line 13

def requirement(name, *args)
  const_name = "#{name.to_s.capitalize}Requirement".to_sym
  requirements[name] = Requirements.const_get(const_name).new(*args)
end

.requirementsObject



46
47
48
# File 'lib/twitter_cldr/resources/importer.rb', line 46

def requirements
  @requirements ||= {}
end

.ruby_engine(engine) ⇒ Object



18
19
20
# File 'lib/twitter_cldr/resources/importer.rb', line 18

def ruby_engine(engine)
  @ruby_engine = engine
end

Instance Method Details

#can_import?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/twitter_cldr/resources/importer.rb', line 72

def can_import?
  importability_errors.empty?
end

#importObject



76
77
78
79
80
81
82
83
84
# File 'lib/twitter_cldr/resources/importer.rb', line 76

def import
  if can_import?
    puts "Importing #{name}..."
    prepare
    execute
  else
    raise "Can't import #{name}: #{importability_errors.first}"
  end
end

#prepareObject



86
87
88
89
90
# File 'lib/twitter_cldr/resources/importer.rb', line 86

def prepare
  before_prepare
  requirements.each { |_, req| req.prepare }
  after_prepare
end