Class: Timezone::Parser::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/timezone/parser/data.rb

Overview

The resulting JSON data structure for a timezone file.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dstObject

Returns the value of attribute dst.



31
32
33
# File 'lib/timezone/parser/data.rb', line 31

def dst
  @dst
end

#nameObject

Returns the value of attribute name.



31
32
33
# File 'lib/timezone/parser/data.rb', line 31

def name
  @name
end

#offsetObject

Returns the value of attribute offset.



31
32
33
# File 'lib/timezone/parser/data.rb', line 31

def offset
  @offset
end

#start_dateObject

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_dateObject



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

Returns:

  • (Boolean)


54
55
56
# File 'lib/timezone/parser/data.rb', line 54

def has_end_date?
  !!@end_date
end

#to_hashObject



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_jsonObject



70
71
72
# File 'lib/timezone/parser/data.rb', line 70

def to_json
  to_hash.to_json
end