Class: TimezoneParser::RailsZone
- Defined in:
- lib/timezone_parser/rails_zone.rb
Overview
Rails zone
Constant Summary
Constants inherited from ZoneInfo
ZoneInfo::TIMEZONE_TYPE_DAYLIGHT, ZoneInfo::TIMEZONE_TYPE_STANDARD
Instance Attribute Summary collapse
-
#Locales ⇒ Object
Returns the value of attribute Locales.
-
#Regions ⇒ Object
Returns the value of attribute Regions.
-
#Types ⇒ Object
Returns the value of attribute Types.
Attributes inherited from ZoneInfo
Class Method Summary collapse
-
.getMetazones(name, locales = nil) ⇒ Array<String>
Get Metazone identifiers for given Rails zone name.
-
.getOffsets(name, toTime = nil, fromTime = nil, locales = nil, types = nil) ⇒ Array<Fixnum>
Get UTC offsets in seconds for given Rails zone name.
-
.getTimezones(name, locales = nil) ⇒ Array<String>
Get Timezone identifiers for given Rails zone name.
-
.getZone(name, locales = nil) ⇒ String
Rails zone identifier.
-
.isValid?(name, locales = nil) ⇒ Boolean
Check if given Rails zone name is a valid timezone.
-
.Locales ⇒ Array<String>
Locales which will be used for RailsZone methods if not specified there.
-
.Regions ⇒ Array<String>
Regions which will be used for WindowsZone methods if not specified there.
Instance Method Summary collapse
-
#getZone ⇒ String
Rails zone identifier.
-
#initialize(name) ⇒ RailsZone
constructor
Rails zone instance.
-
#isValid? ⇒ Boolean
Check if Rails zone is valid.
-
#set(locales = nil, regions = nil, types = nil) ⇒ WindowsZone
Set locales and regions.
Methods inherited from ZoneInfo
#getMetazones, #getOffsets, #getTimezones, #getTypes, #reset, #setTime
Constructor Details
#initialize(name) ⇒ RailsZone
Rails zone instance
35 36 37 38 39 40 |
# File 'lib/timezone_parser/rails_zone.rb', line 35 def initialize(name) @Name = name @Valid = nil setTime set(@@Locales.dup, @@Regions.dup) end |
Instance Attribute Details
#Locales ⇒ Object
Returns the value of attribute Locales.
29 30 31 |
# File 'lib/timezone_parser/rails_zone.rb', line 29 def Locales @Locales end |
#Regions ⇒ Object
Returns the value of attribute Regions.
30 31 32 |
# File 'lib/timezone_parser/rails_zone.rb', line 30 def Regions @Regions end |
#Types ⇒ Object
Returns the value of attribute Types.
31 32 33 |
# File 'lib/timezone_parser/rails_zone.rb', line 31 def Types @Types end |
Class Method Details
.getMetazones(name, locales = nil) ⇒ Array<String>
Get Metazone identifiers for given Rails zone name
121 122 123 |
# File 'lib/timezone_parser/rails_zone.rb', line 121 def self.getMetazones(name, locales = nil) self.new(name).set(locales).getMetazones end |
.getOffsets(name, toTime = nil, fromTime = nil, locales = nil, types = nil) ⇒ Array<Fixnum>
Get UTC offsets in seconds for given Rails zone name
102 103 104 |
# File 'lib/timezone_parser/rails_zone.rb', line 102 def self.getOffsets(name, toTime = nil, fromTime = nil, locales = nil, types = nil) self.new(name).setTime(toTime, fromTime).set(locales, nil, types).getOffsets end |
.getTimezones(name, locales = nil) ⇒ Array<String>
Get Timezone identifiers for given Rails zone name
111 112 113 |
# File 'lib/timezone_parser/rails_zone.rb', line 111 def self.getTimezones(name, locales = nil) self.new(name).set(locales).getTimezones end |
.getZone(name, locales = nil) ⇒ String
Rails zone identifier
129 130 131 |
# File 'lib/timezone_parser/rails_zone.rb', line 129 def self.getZone(name, locales = nil) self.new(name).set(locales).getZone end |
.isValid?(name, locales = nil) ⇒ Boolean
Check if given Rails zone name is a valid timezone
91 92 93 |
# File 'lib/timezone_parser/rails_zone.rb', line 91 def self.isValid?(name, locales = nil) self.new(name).set(locales).isValid? end |
.Locales ⇒ Array<String>
Locales which will be used for RailsZone methods if not specified there
Each locale is language identifier based on IETF BCP 47 and ISO 639 code
16 17 18 |
# File 'lib/timezone_parser/rails_zone.rb', line 16 def self.Locales @@Locales end |
.Regions ⇒ Array<String>
Regions which will be used for WindowsZone methods if not specified there
Each region is either ISO 3166-1 alpha-2 code
25 26 27 |
# File 'lib/timezone_parser/rails_zone.rb', line 25 def self.Regions @@Regions end |
Instance Method Details
#getZone ⇒ String
Rails zone identifier
79 80 81 82 83 84 |
# File 'lib/timezone_parser/rails_zone.rb', line 79 def getZone unless @Zone @Zone = self.getFilteredData(:Zone).first end @Zone end |
#isValid? ⇒ Boolean
Check if Rails zone is valid
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/timezone_parser/rails_zone.rb', line 57 def isValid? if @Valid.nil? params = [] joins = '' where = '' if not @Locales.empty? joins += ' LEFT JOIN `Locales` AS L ON RI.Locale = L.ID' where = 'L.Name COLLATE NOCASE IN (' + Array.new(@Locales.count, '?').join(',') + ') AND ' params += @Locales end sql = "SELECT 1 FROM `RailsI18N` RI #{joins} WHERE #{where}RI.`NameLowercase` = ? LIMIT 1" params << @Name.downcase @Valid = Data::Storage.getStatement(sql).execute(*params).count > 0 end @Valid end |
#set(locales = nil, regions = nil, types = nil) ⇒ WindowsZone
Set locales and regions
48 49 50 51 52 53 |
# File 'lib/timezone_parser/rails_zone.rb', line 48 def set(locales = nil, regions = nil, types = nil) @Locales = locales unless locales.nil? @Regions = regions unless regions.nil? @Types = types unless types.nil? self end |