forked from carmen-ruby/carmen
/
carmen.rb
72 lines (61 loc) · 2.16 KB
/
carmen.rb
1
2
3
4
5
6
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require 'yaml'
require 'pathname'
lib_path = File.expand_path('../../lib', __FILE__)
$LOAD_PATH.unshift(lib_path)
require 'carmen/country'
require 'carmen/i18n'
require 'carmen/version'
module Carmen
class << self
# Public: Where the data files for Carmen are stored.
#
# Should be in the following format:
# |- world.yml (all countries)
# \- regions (directory for subregions, named by code)
# |- be.yml (subregion file for a country)
#
# Defaults to the `iso_data` directory within the Carmen directory.
attr_reader :data_path
# Public: Where to store overlay data.
#
# Overlay data is loaded after the data in `data_path`. Entries that appear
# within the `overlay_path` take precedence.
#
# The files in this directory should be in an identical layout to those in
# `data_path`. There should only be a file in the overlay directory if the
# corresponding regoins has overlay data. Only the regions to be modified
# should be included in an overlay file.
#
# Defaults to nil (no overlay data).
attr_reader :overlay_path
# Public: an object to use as the I18n backend.
#
# Ths suppiled object must respond to
# t(key).
#
# Defaults to an instance of Carmen::I18n::Simple.
attr_accessor :i18n_backend
# Private: the Carmen library's root directory.
#
# Provides a way to find the built-in data and locale files.
attr_accessor :root_path
# Public: Set the data path.
# path - The String path to the data directory.
def data_path=(path)
raise "Carmen's data_path cannot be nil" if path.nil?
@data_path = Pathname.new(path)
World.instance.reset!
end
# Public: Set the overlay data path.
# path - The String path to the overlay data directory.
def overlay_path=(path)
path = Pathname.new(path) unless path.nil?
@overlay_path = path
World.instance.reset!
end
end
self.data_path = File.expand_path('../../iso_data', __FILE__)
locale_path = File.expand_path('../locale', data_path)
self.i18n_backend = Carmen::I18n::Simple.new(locale_path)
self.root_path = File.expand_path('../..', __FILE__)
end