Class: TZInfo::TZDataDefinition
- Inherits:
-
Object
- Object
- TZInfo::TZDataDefinition
- Defined in:
- lib/tzinfo/tzdataparser.rb
Overview
Base class for Zones and Links.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
:nodoc:.
-
#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.
488 489 490 491 492 493 494 495 |
# File 'lib/tzinfo/tzdataparser.rb', line 488 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)
:nodoc:
484 485 486 |
# File 'lib/tzinfo/tzdataparser.rb', line 484 def name @name end |
#name_elements ⇒ Object (readonly)
Returns the value of attribute name_elements.
485 486 487 |
# File 'lib/tzinfo/tzdataparser.rb', line 485 def name_elements @name_elements end |
#path_elements ⇒ Object (readonly)
Returns the value of attribute path_elements.
486 487 488 |
# File 'lib/tzinfo/tzdataparser.rb', line 486 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.
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
# File 'lib/tzinfo/tzdataparser.rb', line 499 def create_file(output_dir) dir = output_dir + File::SEPARATOR + 'definitions' + File::SEPARATOR + @path_elements.join(File::SEPARATOR) FileUtils.mkdir_p(dir) File.open(output_dir + File::SEPARATOR + 'definitions' + File::SEPARATOR + @name_elements.join(File::SEPARATOR) + '.rb', 'w') {|file| file.binmode 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('require \'tzinfo/timezone_definition\'') file.puts('') file.puts('module TZInfo') 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 TZInfo } end |