Class: ArgCollection
- Inherits:
-
Object
- Object
- ArgCollection
- Defined in:
- lib/pretty_args.rb
Instance Attribute Summary collapse
-
#arg_length ⇒ Object
Returns the value of attribute arg_length.
-
#args ⇒ Object
Returns the value of attribute args.
-
#description_width ⇒ Object
Returns the value of attribute description_width.
Instance Method Summary collapse
- #add(label, description) ⇒ Object
- #add_arg(ar) ⇒ Object
- #add_args(args) ⇒ Object
- #draw ⇒ Object
-
#initialize(*args) ⇒ ArgCollection
constructor
A new instance of ArgCollection.
Constructor Details
#initialize(*args) ⇒ ArgCollection
Returns a new instance of ArgCollection.
30 31 32 33 34 35 36 37 38 |
# File 'lib/pretty_args.rb', line 30 def initialize *args @args = [] @arg_length = 0 @description_width = 40 if !args.empty? add_args args end end |
Instance Attribute Details
#arg_length ⇒ Object
Returns the value of attribute arg_length.
28 29 30 |
# File 'lib/pretty_args.rb', line 28 def arg_length @arg_length end |
#args ⇒ Object
Returns the value of attribute args.
28 29 30 |
# File 'lib/pretty_args.rb', line 28 def args @args end |
#description_width ⇒ Object
Returns the value of attribute description_width.
28 29 30 |
# File 'lib/pretty_args.rb', line 28 def description_width @description_width end |
Instance Method Details
#add(label, description) ⇒ Object
40 41 42 |
# File 'lib/pretty_args.rb', line 40 def add label, description add_arg Arg.new(label, description) end |
#add_arg(ar) ⇒ Object
44 45 46 47 |
# File 'lib/pretty_args.rb', line 44 def add_arg ar @args << ar @arg_length += ar.label.length + 3 end |
#add_args(args) ⇒ Object
49 50 51 52 53 |
# File 'lib/pretty_args.rb', line 49 def add_args args args.each do |a| add_arg a end end |
#draw ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/pretty_args.rb', line 55 def draw @args.each { |arg| print arg.label + " " } puts "" @args.each { |arg| print (" "*arg.hl), "┬", (" "*arg.hl), " " } puts "" @args.each { |arg| print (" "*arg.hl), "│", (" "*arg.hl), " " } puts "" r = @args.size - 1 for u in 0..r i = @args.size - u - 1; m = "" for k in 0..(i-1) m += (" "*@args[k].hl) + "│" + (" "*@args[k].hl) + " " end s = m + (" "*@args[i].hl) p = (s+ "└").ljust(@arg_length , "─") print p + ' ' t = @args[i].description puts t.slice!(0..40) while !t.empty? puts s.ljust(@arg_length , " ") + ' ' + t.slice!(0..40) end end end |