Class: TZInfo::Data::TZDataParser
- Inherits:
-
Object
- Object
- TZInfo::Data::TZDataParser
- Includes:
- TZDataParserUtils
- Defined in:
- lib/tzinfo/data/tzdataparser.rb
Overview
Parses Time Zone Data from the IANA Time Zone Database and transforms it into a set of Ruby modules that can be used with TZInfo.
Normally, this class wouldn’t be used. It is only run to update the timezone data and index modules.
Constant Summary collapse
- DEFAULT_MIN_YEAR =
Default earliest year that will be considered.
1800
- DEFAULT_FUTURE_YEARS =
Default number of future years data to generate (not including the current year).
50
Instance Attribute Summary collapse
-
#exclude_zones ⇒ Object
Zones to exclude from generation when not using only_zones (set to an array containing zone identifiers).
-
#generate_countries ⇒ Object
Whether to generate country definitions (set to false to stop countries being generated).
-
#generate_zones ⇒ Object
Whether to generate zone definitions (set to false to stop zones being generated).
-
#max_year ⇒ Object
Latest year that will be considered.
-
#min_year ⇒ Object
Earliest year that will be considered.
-
#only_zones ⇒ Object
Limit the set of zones to generate (set to an array containing zone identifiers).
Instance Method Summary collapse
-
#execute ⇒ Object
Reads the tzdata source and generates the classes.
-
#initialize(input_dir, output_dir) ⇒ TZDataParser
constructor
Initializes a new TZDataParser.
Constructor Details
#initialize(input_dir, output_dir) ⇒ TZDataParser
Initializes a new TZDataParser. input_dir must contain the extracted tzdata tarball. output_dir is the location to output the modules (in definitions and indexes directories).
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/tzinfo/data/tzdataparser.rb', line 153 def initialize(input_dir, output_dir) super() @input_dir = input_dir @output_dir = output_dir @min_year = DEFAULT_MIN_YEAR @max_year = Time.now.year + DEFAULT_FUTURE_YEARS @rule_sets = {} @zones = {} @countries = {} @no_rules = TZDataNoRules.new @generate_zones = true @generate_countries = true @only_zones = [] @exclude_zones = [] end |
Instance Attribute Details
#exclude_zones ⇒ Object
Zones to exclude from generation when not using only_zones (set to an array containing zone identifiers).
148 149 150 |
# File 'lib/tzinfo/data/tzdataparser.rb', line 148 def exclude_zones @exclude_zones end |
#generate_countries ⇒ Object
Whether to generate country definitions (set to false to stop countries being generated).
140 141 142 |
# File 'lib/tzinfo/data/tzdataparser.rb', line 140 def generate_countries @generate_countries end |
#generate_zones ⇒ Object
Whether to generate zone definitions (set to false to stop zones being generated).
136 137 138 |
# File 'lib/tzinfo/data/tzdataparser.rb', line 136 def generate_zones @generate_zones end |
#max_year ⇒ Object
Latest year that will be considered. Defaults to the current year plus FUTURE_YEARS.
132 133 134 |
# File 'lib/tzinfo/data/tzdataparser.rb', line 132 def max_year @max_year end |
#min_year ⇒ Object
Earliest year that will be considered. Defaults to DEFAULT_MIN_YEAR.
128 129 130 |
# File 'lib/tzinfo/data/tzdataparser.rb', line 128 def min_year @min_year end |
#only_zones ⇒ Object
Limit the set of zones to generate (set to an array containing zone identifiers).
144 145 146 |
# File 'lib/tzinfo/data/tzdataparser.rb', line 144 def only_zones @only_zones end |
Instance Method Details
#execute ⇒ Object
Reads the tzdata source and generates the classes. Progress information is written to standard out.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/tzinfo/data/tzdataparser.rb', line 171 def execute files = Dir.entries(@input_dir).select do |file| file =~ /\A[^\.]+\z/ && !%w(README Makefile).include?(file) && File.file?(File.join(@input_dir, file)) end files.each {|file| load_rules(file) } files.each {|file| load_zones(file) } files.each {|file| load_links(file) } load_countries if @generate_zones modules = [] if @only_zones.nil? || @only_zones.empty? @zones.each_value {|zone| zone.write_module(@output_dir) unless @exclude_zones.include?(zone.name) } else @only_zones.each {|id| zone = @zones[id] zone.write_module(@output_dir) } end write_timezones_index end if @generate_countries write_countries_index end end |