class TwitterCldr::Timezones::ZoneMeta

Constants

WORLD

Public Class Methods

canonical_country_for(tz_id) click to toggle source
# File lib/twitter_cldr/timezones/zone_meta.rb, line 81
def canonical_country_for(tz_id)
  region = region_for_tz(tz_id)
  return nil if region == WORLD
  region
end
is_primary_region?(region_code, tz_id) click to toggle source
# File lib/twitter_cldr/timezones/zone_meta.rb, line 93
def is_primary_region?(region_code, tz_id)
  if region = regions_resource[tz_id.to_sym]
    return region[:primary] && region[:region] == region_code
  end

  false
end
normalize(tz_id) click to toggle source
# File lib/twitter_cldr/timezones/zone_meta.rb, line 72
def normalize(tz_id)
  tz_id = tz_id.to_s.strip
  bcp47_aliases[tz_id.to_sym] || tz_id
end
region_for_tz(tz_id) click to toggle source
# File lib/twitter_cldr/timezones/zone_meta.rb, line 87
def region_for_tz(tz_id)
  if region = regions_resource[tz_id.to_sym]
    region[:region]
  end
end
short_name_for(tz_id) click to toggle source
# File lib/twitter_cldr/timezones/zone_meta.rb, line 77
def short_name_for(tz_id)
  bcp47_short_names[tz_id.to_sym]
end
tz_metazone_for(tz_id, date) click to toggle source
# File lib/twitter_cldr/timezones/zone_meta.rb, line 105
def tz_metazone_for(tz_id, date)
  tz_metazones_for(tz_id).find { |mz| mz.includes?(date) }
end
tz_metazones_for(tz_id) click to toggle source
# File lib/twitter_cldr/timezones/zone_meta.rb, line 101
def tz_metazones_for(tz_id)
  tz_metazone_map[tz_id.to_sym] || []
end

Private Class Methods

aliases() click to toggle source
# File lib/twitter_cldr/timezones/zone_meta.rb, line 111
def aliases
  @aliases ||= aliases_resource[:zone].each_with_object({}) do |(_, zones), ret|
    ret.merge!(zones)
  end
end
aliases_resource() click to toggle source
# File lib/twitter_cldr/timezones/zone_meta.rb, line 145
def aliases_resource
  @aliases_resource ||= TwitterCldr.get_resource(:shared, :aliases)[:aliases]
end
bcp47_aliases() click to toggle source
# File lib/twitter_cldr/timezones/zone_meta.rb, line 117
def bcp47_aliases
  @bcp47_aliases ||= bcp47_metadata[:aliases]
end
bcp47_metadata() click to toggle source
# File lib/twitter_cldr/timezones/zone_meta.rb, line 125
def bcp47_metadata
  @bcp47_metadata ||= TwitterCldr.get_resource(:shared, :bcp47_timezone_metadata)
end
bcp47_short_names() click to toggle source
# File lib/twitter_cldr/timezones/zone_meta.rb, line 121
def bcp47_short_names
  @bcp47_short_names ||= bcp47_metadata[:short_names]
end
metazones_resource() click to toggle source
# File lib/twitter_cldr/timezones/zone_meta.rb, line 141
def metazones_resource
  @metazones_resource ||= TwitterCldr.get_resource(:shared, :metazones)
end
primary_zones() click to toggle source
# File lib/twitter_cldr/timezones/zone_meta.rb, line 129
def primary_zones
  metazones_resource[:primaryzones]
end
regions_resource() click to toggle source
# File lib/twitter_cldr/timezones/zone_meta.rb, line 149
def regions_resource
  @regions_resource ||= TwitterCldr.get_resource(:shared, :timezone_regions)
end
tz_metazone_map() click to toggle source
# File lib/twitter_cldr/timezones/zone_meta.rb, line 133
def tz_metazone_map
  @tz_metazone_map ||= metazones_resource[:timezones].each_with_object({}) do |(tz_id, metazones), ret|
    ret[tz_id] = metazones.map do |mz|
      TimezoneMetazone.new(tz_id, mz[:metazone], mz[:from], mz[:to])
    end
  end
end