Class: RTFM::SynopsisSection

Inherits:
Object
  • Object
show all
Defined in:
lib/rtfm/sections/synopsis.rb

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ SynopsisSection

Returns a new instance of SynopsisSection.

Yields:

  • (_self)

Yield Parameters:



3
4
5
6
# File 'lib/rtfm/sections/synopsis.rb', line 3

def initialize
  @options = []
  yield self if block_given?
end

Instance Method Details

#add_option(*args) ⇒ Object Also known as: option



8
9
10
11
12
13
# File 'lib/rtfm/sections/synopsis.rb', line 8

def add_option(*args)
  if args.size == 1 && args.first.is_a?(Option)
  then @options << args.first
  else @options << Option.new(*args)
  end
end

#compare_flags(a, b) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/rtfm/sections/synopsis.rb', line 16

def compare_flags(a, b)
  a_ord, b_ord = a.ord, b.ord
  if ('0'.ord .. '9'.ord).include?(a_ord)
    a_ord += 'z'.ord
  end
  if ('0'.ord .. '9'.ord).include?(b_ord)
    b_ord += 'z'.ord
  end
  a_ord <=> b_ord
end

#to_groffObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rtfm/sections/synopsis.rb', line 27

def to_groff
  flags = @options.select {|opt| opt.title.size == 1 && !opt.argument}
  long_args = @options - flags
  
  GroffString.groffify do |out|
    out.section "synopsis"
    out.put_name
    out.Op "Fl", flags.map {|flag| flag.title}.sort {|a, b| compare_flags(a,b)}.join
    long_args.each do |opt|
      out << opt.to_groff(:option)
    end
  end
end