Class: Timezone::Parser::Data
- Inherits:
-
Object
- Object
- Timezone::Parser::Data
- Defined in:
- lib/timezone/parser/data.rb
Overview
The resulting JSON data structure for a timezone file.
Instance Attribute Summary collapse
-
#dst ⇒ Object
Returns the value of attribute dst.
-
#name ⇒ Object
Returns the value of attribute name.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
Instance Method Summary collapse
- #end_date ⇒ Object
- #end_date=(date) ⇒ Object
- #has_end_date? ⇒ Boolean
-
#initialize(start_date, end_date, zone, rule = NilRule.new) ⇒ Data
constructor
A new instance of Data.
- #to_hash ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(start_date, end_date, zone, rule = NilRule.new) ⇒ Data
Returns a new instance of Data.
33 34 35 36 37 38 39 40 |
# File 'lib/timezone/parser/data.rb', line 33 def initialize(start_date, end_date, zone, rule = NilRule.new) @dst = rule.dst? @offset = parse_offset(zone, rule) @name = parse_name(zone.format, rule.letter) @utime = rule.utime? @start_date = parse_start_date(start_date) self.end_date = end_date end |
Instance Attribute Details
#dst ⇒ Object
Returns the value of attribute dst.
31 32 33 |
# File 'lib/timezone/parser/data.rb', line 31 def dst @dst end |
#name ⇒ Object
Returns the value of attribute name.
31 32 33 |
# File 'lib/timezone/parser/data.rb', line 31 def name @name end |
#offset ⇒ Object
Returns the value of attribute offset.
31 32 33 |
# File 'lib/timezone/parser/data.rb', line 31 def offset @offset end |
#start_date ⇒ Object
Returns the value of attribute start_date.
31 32 33 |
# File 'lib/timezone/parser/data.rb', line 31 def start_date @start_date end |
Instance Method Details
#end_date ⇒ Object
50 51 52 |
# File 'lib/timezone/parser/data.rb', line 50 def end_date @end_date || END_DATE end |
#end_date=(date) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/timezone/parser/data.rb', line 42 def end_date=(date) if date.nil? || @utime @end_date = date else @end_date = date - (@offset * 1_000) end end |
#has_end_date? ⇒ Boolean
54 55 56 |
# File 'lib/timezone/parser/data.rb', line 54 def has_end_date? !!@end_date end |
#to_hash ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/timezone/parser/data.rb', line 58 def to_hash { '_from' => _from, 'from' => @start_date, '_to' => _to, 'to' => end_date, 'dst' => @dst, 'offset' => @offset, 'name' => @name } end |
#to_json ⇒ Object
70 71 72 |
# File 'lib/timezone/parser/data.rb', line 70 def to_json to_hash.to_json end |