Class: PVN::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.
12 13 14 |
# File 'lib/synoption/doc.rb', line 12 def initialize option @option = option end |
Instance Method Details
#re_to_string(re) ⇒ Object
returns an option regexp as a ‘cleaner’ string
25 26 27 |
# File 'lib/synoption/doc.rb', line 25 def re_to_string re re.source.gsub(%r{\\d\+?}, 'N').gsub(%r{[\^\?\$\\\(\)]}, '') end |
#to_doc(io) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/synoption/doc.rb', line 56 def to_doc io opttag = @option.tag optdesc = @option.description # wrap optdesc? @option.description.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.regexp io.puts to_doc_line re_to_string(re), "same as above", ":" end if @option.negate 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
51 52 53 54 |
# File 'lib/synoption/doc.rb', line 51 def to_doc_line lhs, rhs, sep = "" fmt = " %-24s %1s %s" sprintf fmt, lhs, sep, rhs end |
#to_doc_negate ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/synoption/doc.rb', line 29 def to_doc_negate doc = nil @option.negate.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
16 17 18 19 20 21 22 |
# File 'lib/synoption/doc.rb', line 16 def to_doc_tag tagline = "#{@option.tag} [--#{@option.name}]" if @option.takes_value? tagline << " ARG" end tagline end |