Class: RTFM::SynopsisSection
- Inherits:
-
Object
- Object
- RTFM::SynopsisSection
- Defined in:
- lib/rtfm/sections/synopsis.rb
Instance Method Summary collapse
- #add_argument(*args) ⇒ Object (also: #add_arguments, #argument, #arguments)
- #add_option(*args) ⇒ Object (also: #option)
- #compare_flags(a, b) ⇒ Object
-
#initialize {|_self| ... } ⇒ SynopsisSection
constructor
A new instance of SynopsisSection.
- #to_groff ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ SynopsisSection
Returns a new instance of SynopsisSection.
3 4 5 6 7 |
# File 'lib/rtfm/sections/synopsis.rb', line 3 def initialize @options = [] @arguments = [] yield self if block_given? end |
Instance Method Details
#add_argument(*args) ⇒ Object Also known as: add_arguments, argument, arguments
9 10 11 |
# File 'lib/rtfm/sections/synopsis.rb', line 9 def add_argument(*args) @arguments.concat args end |
#add_option(*args) ⇒ Object Also known as: option
16 17 18 19 20 21 |
# File 'lib/rtfm/sections/synopsis.rb', line 16 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
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rtfm/sections/synopsis.rb', line 24 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_groff ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rtfm/sections/synopsis.rb', line 35 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 @arguments.each do |arg| out.Ar arg end end end |