Class: RTF::Information
- Inherits:
-
Object
- Object
- RTF::Information
- Defined in:
- lib/rtf/information.rb
Overview
This class represents an information group for a RTF document.
Instance Attribute Summary (collapse)
-
- (Object) author
Attribute accessor.
-
- (Object) comments
Attribute accessor.
-
- (Object) company
Attribute accessor.
-
- (Object) created
Attribute accessor.
-
- (Object) title
Attribute accessor.
Instance Method Summary (collapse)
-
- (Information) initialize(title = nil, author = nil, company = nil, comments = nil, creation = nil)
constructor
This is the constructor for the Information class.
-
- (Object) to_rtf(indent = 0)
This method generates the RTF text for an Information object.
-
- (Object) to_s(indent = 0)
This method creates a textual description for an Information object.
Constructor Details
- (Information) initialize(title = nil, author = nil, company = nil, comments = nil, creation = nil)
This is the constructor for the Information class.
Parameters
title |
A string containing the document title information. Defaults to nil. |
author |
A string containing the document author information. Defaults to nil. |
company |
A string containing the company name information. Defaults to nil. |
comments |
A string containing the information comments. Defaults to nil to indicate no comments. |
creation |
A Time object or a String that can be parsed into a Time object (using ParseDate) indicating the document creation date and time. Defaults to nil to indicate the current date and time. |
Exceptions
RTFError |
Generated whenever invalid creation date/time details are specified. |
34 35 36 37 38 39 40 |
# File 'lib/rtf/information.rb', line 34 def initialize(title=nil, =nil, company=nil, comments=nil, creation=nil) @title = title @author = @company = company @comments = comments self.created = (creation == nil ? Time.new : creation) end |
Instance Attribute Details
- (Object) author
Attribute accessor.
9 10 11 |
# File 'lib/rtf/information.rb', line 9 def @author end |
- (Object) comments
Attribute accessor.
9 10 11 |
# File 'lib/rtf/information.rb', line 9 def comments @comments end |
- (Object) company
Attribute accessor.
9 10 11 |
# File 'lib/rtf/information.rb', line 9 def company @company end |
- (Object) created
Attribute accessor.
9 10 11 |
# File 'lib/rtf/information.rb', line 9 def created @created end |
- (Object) title
Attribute accessor.
9 10 11 |
# File 'lib/rtf/information.rb', line 9 def title @title end |
Instance Method Details
- (Object) to_rtf(indent = 0)
This method generates the RTF text for an Information object.
Parameters
indent |
The number of spaces to prefix to the lines generated by the method. Defaults to zero. |
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rtf/information.rb', line 92 def to_rtf(indent=0) prefix = indent > 0 ? ' ' * indent : '' text = StringIO.new text << "#{prefix}{\\info" text << "\n#{prefix}{\\title #{@title}}" if @title != nil text << "\n#{prefix}{\\author #{@author}}" if @author != nil text << "\n#{prefix}{\\company #{@company}}" if @company != nil text << "\n#{prefix}{\\doccomm #{@comments}}" if @comments != nil if @created != nil text << "\n#{prefix}{\\createim\\yr#{@created.year}" text << "\\mo#{@created.month}\\dy#{@created.day}" text << "\\hr#{@created.hour}\\min#{@created.min}}" end text << "\n#{prefix}}" text.string end |
- (Object) to_s(indent = 0)
This method creates a textual description for an Information object.
Parameters
indent |
The number of spaces to prefix to the lines generated by the method. Defaults to zero. |
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rtf/information.rb', line 73 def to_s(indent=0) prefix = indent > 0 ? ' ' * indent : '' text = StringIO.new text << "#{prefix}Information" text << "\n#{prefix} Title: #{@title}" if @title != nil text << "\n#{prefix} Author: #{@author}" if @author != nil text << "\n#{prefix} Company: #{@company}" if @company != nil text << "\n#{prefix} Comments: #{@comments}" if @comments != nil text << "\n#{prefix} Created: #{@created}" if @created != nil text.string end |