Class: Ragol::Doc
Overview
documentation for an option.
Instance Method Summary collapse
-
#initialize(option) ⇒ Doc
constructor
A new instance of Doc.
-
#re_to_string(re) ⇒ Object
returns an option regexp as a ‘cleaner’ string.
- #to_doc(io) ⇒ Object
-
#to_doc_line(lhs, rhs, sep = "") ⇒ Object
-g [–use-merge-history] : use/display additional information from merge 01234567890123456789012345678901234567890123456789012345678901234567890123456789 0 1 2 3 4 5 6.
- #to_doc_negate ⇒ Object
- #to_doc_tag ⇒ Object
Constructor Details
#initialize(option) ⇒ Doc
Returns a new instance of Doc.
11 12 13 |
# File 'lib/ragol/doc.rb', line 11 def initialize option @option = option end |
Instance Method Details
#re_to_string(re) ⇒ Object
returns an option regexp as a ‘cleaner’ string
26 27 28 |
# File 'lib/ragol/doc.rb', line 26 def re_to_string re re.source.gsub(%r{\\d\+?}, 'N').gsub(%r{[\^\?\$\\\(\)]}, '') end |
#to_doc(io) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ragol/doc.rb', line 57 def to_doc io # wrap optdesc? [ @option.description ].flatten.each_with_index do |descline, idx| lhs = idx == 0 ? to_doc_tag : "" io.puts to_doc_line lhs, descline, idx == 0 ? ":" : "" end if defval = @option.default io.puts to_doc_line "", " default: #{defval}" end if re = @option.matchers.regexps io.puts to_doc_line re_to_string(re), "same as above", ":" end if @option.matchers.negatives lhs = to_doc_negate io.puts to_doc_line lhs, "", "" end end |
#to_doc_line(lhs, rhs, sep = "") ⇒ Object
-g [–use-merge-history] : use/display additional information from merge 01234567890123456789012345678901234567890123456789012345678901234567890123456789 0 1 2 3 4 5 6
52 53 54 55 |
# File 'lib/ragol/doc.rb', line 52 def to_doc_line lhs, rhs, sep = "" fmt = " %-24s %1s %s" sprintf fmt, lhs, sep, rhs end |
#to_doc_negate ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ragol/doc.rb', line 30 def to_doc_negate doc = nil @option.matchers.negatives.elements.each do |neg| str = if neg.kind_of? Regexp str = re_to_string neg else str = neg end if doc doc << " [#{str}]" else doc = str end end doc end |
#to_doc_tag ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/ragol/doc.rb', line 15 def to_doc_tag = @option.matchers..elements longopts, shortopts = .partition { |tag| tag[0 .. 1] == '--' } tagline = [ shortopts, longopts ].flatten.join ', ' if @option.takes_value? tagline << " ARG" end tagline end |