Class: RTFM::ManPage
- Inherits:
-
Struct
- Object
- Struct
- RTFM::ManPage
- Defined in:
- lib/rtfm/manpage.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#name ⇒ Object
Returns the value of attribute name.
-
#section ⇒ Object
Returns the value of attribute section.
-
#summary ⇒ Object
Returns the value of attribute summary.
Class Method Summary collapse
- .add_section(name, klass) ⇒ Object
- .all_pages ⇒ Object
- .text_section(*args) ⇒ Object (also: text_sections)
Instance Method Summary collapse
- #add_option(name, desc, opts = {}) ⇒ Object (also: #option)
-
#initialize(name, section = nil) {|_self| ... } ⇒ ManPage
constructor
A new instance of ManPage.
- #to_groff ⇒ Object
Constructor Details
#initialize(name, section = nil) {|_self| ... } ⇒ ManPage
Returns a new instance of ManPage.
40 41 42 43 44 45 |
# File 'lib/rtfm/manpage.rb', line 40 def initialize(name, section=nil) self.class.all_pages << self self.name, self.section = name, section self.date = DateTime.now yield self end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date
2 3 4 |
# File 'lib/rtfm/manpage.rb', line 2 def date @date end |
#name ⇒ Object
Returns the value of attribute name
2 3 4 |
# File 'lib/rtfm/manpage.rb', line 2 def name @name end |
#section ⇒ Object
Returns the value of attribute section
2 3 4 |
# File 'lib/rtfm/manpage.rb', line 2 def section @section end |
#summary ⇒ Object
Returns the value of attribute summary
2 3 4 |
# File 'lib/rtfm/manpage.rb', line 2 def summary @summary end |
Class Method Details
.add_section(name, klass) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rtfm/manpage.rb', line 18 def add_section(name, klass) klass = klass.to_s.intern class_eval %Q{ def #{name} @#{name} ||= #{klass}.new yield @#{name} if block_given? @#{name} end } end |
.all_pages ⇒ Object
29 30 31 |
# File 'lib/rtfm/manpage.rb', line 29 def all_pages @pages ||= [] end |
.text_section(*args) ⇒ Object Also known as: text_sections
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rtfm/manpage.rb', line 4 def text_section(*args) args.each do |sect| class_eval %Q{ def #{sect} @#{sect} ||= TextSection.new(:#{sect}, "") end def #{sect}=(str) @#{sect} = TextSection.new(:#{sect}, str) end } end end |
Instance Method Details
#add_option(name, desc, opts = {}) ⇒ Object Also known as: option
47 48 49 50 51 52 53 |
# File 'lib/rtfm/manpage.rb', line 47 def add_option(name, desc, opts={}) opt = Option.new(name, desc, opts) description.add_option opt unless opts.has_key?(:synopsis) && !opts.delete(:synopsis) synopsis.add_option(opt) end end |
#to_groff ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rtfm/manpage.rb', line 56 def to_groff GroffString.groffify do |out| out.Dd date.strftime("%B %d, %Y") out.Os out.Dt name, (section || "") out.section "NAME" out.Nm name out.Nd summary [@synopsis, @description, @see_also, @history, @authors, @bugs].each do |sect| out << sect.to_groff if sect end end end |