Class: RTF::Information

Inherits:
Object
  • Object
show all
Defined in:
lib/rtf/information.rb

Overview

This class represents an information group for a RTF document.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title = nil, author = nil, company = nil, comments = nil, creation = nil) ⇒ Information

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, author=nil, company=nil, comments=nil, creation=nil)
   @title       = title
   @author      = author
   @company     = company
   @comments    = comments
   self.created = (creation == nil ? Time.new : creation)
end

Instance Attribute Details

#authorObject

Attribute accessor.



9
10
11
# File 'lib/rtf/information.rb', line 9

def author
  @author
end

#commentsObject

Attribute accessor.



9
10
11
# File 'lib/rtf/information.rb', line 9

def comments
  @comments
end

#companyObject

Attribute accessor.



9
10
11
# File 'lib/rtf/information.rb', line 9

def company
  @company
end

#createdObject

Attribute accessor.



9
10
11
# File 'lib/rtf/information.rb', line 9

def created
  @created
end

#titleObject

Attribute accessor.



9
10
11
# File 'lib/rtf/information.rb', line 9

def title
  @title
end

Instance Method Details

#to_rtf(indent = 0) ⇒ Object

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

#to_s(indent = 0) ⇒ Object

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