Class: TimezoneParser::Abbreviation
- Defined in:
- lib/timezone_parser/abbreviation.rb
Overview
Timezone abbreviation
Constant Summary
Constants inherited from ZoneInfo
ZoneInfo::TIMEZONE_TYPE_DAYLIGHT, ZoneInfo::TIMEZONE_TYPE_STANDARD
Instance Attribute Summary collapse
-
#Regions ⇒ Object
Returns the value of attribute Regions.
-
#Type ⇒ Object
Returns the value of attribute Type.
Attributes inherited from ZoneInfo
Class Method Summary collapse
-
.couldBeValid?(abbreviation) ⇒ Boolean
Check if given Timezone abbreviation (case-insensitive) could be a valid timezone.
-
.getMetazones(abbreviation) ⇒ Object
Get Metazone identifiers for given Timezone abbreviation.
-
.getOffsets(abbreviation, toTime = nil, fromTime = nil, regions = nil, type = nil) ⇒ Array<Fixnum>
Get UTC offsets in seconds for given Timezone abbreviation.
-
.getTimezones(abbreviation, toTime = nil, fromTime = nil, regions = nil, type = nil) ⇒ Array<String>
Get Timezone identifiers for given Timezone abbreviation.
-
.isValid?(abbreviation) ⇒ Boolean
Check if given Timezone abbreviation (case-sensitive) is a valid timezone.
-
.Regions ⇒ Array<String>
Regions which will be used for Abbreviation methods if not specified there.
Instance Method Summary collapse
-
#initialize(abbreviation) ⇒ Abbreviation
constructor
Abbreviation instance.
-
#isValid? ⇒ Boolean
Check if abbreviation is valid.
-
#set(regions = nil, type = nil) ⇒ Abbreviation
Set regions and type.
Methods inherited from ZoneInfo
#getMetazones, #getOffsets, #getTimezones, #getTypes, #reset, #setTime
Constructor Details
#initialize(abbreviation) ⇒ Abbreviation
Abbreviation instance
24 25 26 27 28 |
# File 'lib/timezone_parser/abbreviation.rb', line 24 def initialize(abbreviation) @Abbreviation = abbreviation setTime set(@@Regions.dup, nil) end |
Instance Attribute Details
#Regions ⇒ Object
Returns the value of attribute Regions.
19 20 21 |
# File 'lib/timezone_parser/abbreviation.rb', line 19 def Regions @Regions end |
#Type ⇒ Object
Returns the value of attribute Type.
20 21 22 |
# File 'lib/timezone_parser/abbreviation.rb', line 20 def Type @Type end |
Class Method Details
.couldBeValid?(abbreviation) ⇒ Boolean
Check if given Timezone abbreviation (case-insensitive) could be a valid timezone
61 62 63 |
# File 'lib/timezone_parser/abbreviation.rb', line 61 def self.couldBeValid?(abbreviation) Data::Storage.getStatement('SELECT 1 FROM `Abbreviations` WHERE `NameLowercase` = ? LIMIT 1').execute(abbreviation.downcase).count > 0 end |
.getMetazones(abbreviation) ⇒ Object
Get Metazone identifiers for given Timezone abbreviation
91 92 93 |
# File 'lib/timezone_parser/abbreviation.rb', line 91 def self.getMetazones(abbreviation) self.new(abbreviation).getMetazones end |
.getOffsets(abbreviation, toTime = nil, fromTime = nil, regions = nil, type = nil) ⇒ Array<Fixnum>
Get UTC offsets in seconds for given Timezone abbreviation
73 74 75 |
# File 'lib/timezone_parser/abbreviation.rb', line 73 def self.getOffsets(abbreviation, toTime = nil, fromTime = nil, regions = nil, type = nil) self.new(abbreviation).setTime(toTime, fromTime).set(regions, type).getOffsets end |
.getTimezones(abbreviation, toTime = nil, fromTime = nil, regions = nil, type = nil) ⇒ Array<String>
Get Timezone identifiers for given Timezone abbreviation
85 86 87 |
# File 'lib/timezone_parser/abbreviation.rb', line 85 def self.getTimezones(abbreviation, toTime = nil, fromTime = nil, regions = nil, type = nil) self.new(abbreviation).setTime(toTime, fromTime).set(regions, type).getTimezones end |
.isValid?(abbreviation) ⇒ Boolean
Check if given Timezone abbreviation (case-sensitive) is a valid timezone
54 55 56 |
# File 'lib/timezone_parser/abbreviation.rb', line 54 def self.isValid?(abbreviation) Data::Storage.getStatement('SELECT 1 FROM `Abbreviations` WHERE `Name` = ? LIMIT 1').execute(abbreviation).count > 0 end |
.Regions ⇒ Array<String>
Regions which will be used for Abbreviation methods if not specified there
Each region is either ISO 3166-1 alpha-2 code
15 16 17 |
# File 'lib/timezone_parser/abbreviation.rb', line 15 def self.Regions @@Regions end |
Instance Method Details
#isValid? ⇒ Boolean
Check if abbreviation is valid
43 44 45 46 47 48 49 |
# File 'lib/timezone_parser/abbreviation.rb', line 43 def isValid? if @Valid.nil? sql = 'SELECT 1 FROM `Abbreviations` WHERE `Name` = ? LIMIT 1' @Valid = Data::Storage.getStatement(sql).execute(@Abbreviation).count > 0 end @Valid end |
#set(regions = nil, type = nil) ⇒ Abbreviation
Set regions and type
35 36 37 38 39 |
# File 'lib/timezone_parser/abbreviation.rb', line 35 def set(regions = nil, type = nil) @Regions = regions unless regions.nil? @Type = type.to_sym if type self end |