Class: TZInfo::Data::TZDataDefinition
- Inherits:
-
Object
- Object
- TZInfo::Data::TZDataDefinition
- Includes:
- TZDataParserUtils
- Defined in:
- lib/tzinfo/data/tzdataparser.rb
Overview
Base class for Zones and Links.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#name_elements ⇒ Object
readonly
Returns the value of attribute name_elements.
-
#path_elements ⇒ Object
readonly
Returns the value of attribute path_elements.
Instance Method Summary collapse
-
#create_file(output_dir) ⇒ Object
Creates necessary directories, the file, writes the class header and footer and yields to a block to write the content.
-
#initialize(name) ⇒ TZDataDefinition
constructor
A new instance of TZDataDefinition.
Constructor Details
#initialize(name) ⇒ TZDataDefinition
Returns a new instance of TZDataDefinition.
558 559 560 561 562 563 564 565 |
# File 'lib/tzinfo/data/tzdataparser.rb', line 558 def initialize(name) @name = name # + and - aren't allowed in class names @name_elements = name.gsub(/-/, '__m__').gsub(/\+/, '__p__').split(/\//) @path_elements = @name_elements.clone @path_elements.pop end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
554 555 556 |
# File 'lib/tzinfo/data/tzdataparser.rb', line 554 def name @name end |
#name_elements ⇒ Object (readonly)
Returns the value of attribute name_elements.
555 556 557 |
# File 'lib/tzinfo/data/tzdataparser.rb', line 555 def name_elements @name_elements end |
#path_elements ⇒ Object (readonly)
Returns the value of attribute path_elements.
556 557 558 |
# File 'lib/tzinfo/data/tzdataparser.rb', line 556 def path_elements @path_elements end |
Instance Method Details
#create_file(output_dir) ⇒ Object
Creates necessary directories, the file, writes the class header and footer and yields to a block to write the content.
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 |
# File 'lib/tzinfo/data/tzdataparser.rb', line 569 def create_file(output_dir) dir = File.join(output_dir, 'definitions', @path_elements.join(File::SEPARATOR)) FileUtils.mkdir_p(dir) open_file(File.join(output_dir, 'definitions', @name_elements.join(File::SEPARATOR)) + '.rb', 'w', :external_encoding => 'UTF-8', :universal_newline => true) do |file| def file.indent(by) if @tz_indent @tz_indent += by else @tz_indent = by end end def file.puts(s) super("#{' ' * (@tz_indent || 0)}#{s}") end file.puts('# encoding: UTF-8') file.puts('') file.puts('# This file contains data derived from the IANA Time Zone Database') file.puts('# (http://www.iana.org/time-zones).') file.puts('') file.puts('module TZInfo') file.indent(2) file.puts('module Data') file.indent(2) file.puts('module Definitions') file.indent(2) @name_elements.each do |part| file.puts("module #{part}") file.indent(2) end file.puts('include TimezoneDefinition') file.puts('') yield file @name_elements.each do file.indent(-2) file.puts('end') end file.indent(-2) file.puts('end') # end module Definitions file.indent(-2) file.puts('end') # end module Data file.indent(-2) file.puts('end') # end module TZInfo end end |