Class: TZInfo::Data::TZDataTransitions

Inherits:
Object
  • Object
show all
Includes:
TZDataParserUtils
Defined in:
lib/tzinfo/data/tzdataparser.rb

Overview

Collection of TZDataTransition instances used when building a zone class.

Instance Method Summary collapse

Constructor Details

#initialize(years) ⇒ TZDataTransitions

Returns a new instance of TZDataTransitions.



811
812
813
814
# File 'lib/tzinfo/data/tzdataparser.rb', line 811

def initialize(years)
  @years = years
  @transitions = []
end

Instance Method Details

#<<(transition) ⇒ Object



816
817
818
# File 'lib/tzinfo/data/tzdataparser.rb', line 816

def << (transition)
  @transitions << transition
end

#output_module(file) ⇒ Object



820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
# File 'lib/tzinfo/data/tzdataparser.rb', line 820

def output_module(file)
  optimize
  
  # Try and end on a transition to std if one happens in the last year.
  if @transitions.length > 1 && 
      @transitions.last.std_offset != 0 &&
      @transitions[@transitions.length - 2].std_offset == 0 &&
      @transitions[@transitions.length - 2].at_utc.year == @years.max
    
    transitions = @transitions[0..@transitions.length - 2]
  else
    transitions = @transitions
  end
  
  process_offsets(file)
  file.puts('')
  
  transitions.each do |t|        
    t.write(file)
  end            
end