Class: RTFM::ManPage

Inherits:
Struct
  • Object
show all
Defined in:
lib/rtfm/manpage.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, section = nil) {|_self| ... } ⇒ ManPage

Returns a new instance of ManPage.

Yields:

  • (_self)

Yield Parameters:

  • _self (RTFM::ManPage)

    the object that the method was called on



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

#dateObject

Returns the value of attribute date

Returns:

  • (Object)

    the current value of date



2
3
4
# File 'lib/rtfm/manpage.rb', line 2

def date
  @date
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



2
3
4
# File 'lib/rtfm/manpage.rb', line 2

def name
  @name
end

#sectionObject

Returns the value of attribute section

Returns:

  • (Object)

    the current value of section



2
3
4
# File 'lib/rtfm/manpage.rb', line 2

def section
  @section
end

#summaryObject

Returns the value of attribute summary

Returns:

  • (Object)

    the current value of 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_pagesObject



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_groffObject



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