pretty_args 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/pretty_args.rb +85 -0
  2. metadata +54 -0
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ # Goal:
5
+ # * * * * * command to be executed
6
+ # ┬ ┬ ┬ ┬ ┬
7
+ # │ │ │ │ │
8
+ # │ │ │ │ │
9
+ # │ │ │ │ └───── day of week (0 - 7) (Sunday=0 or 7)
10
+ # │ │ │ └────────── month (1 - 12)
11
+ # │ │ └─────────────── day of month (1 - 31)
12
+ # │ └──────────────────── hour (0 - 23)
13
+ # └───────────────────────── min (0 - 59)
14
+
15
+ class Arg
16
+ attr_accessor :label, :description
17
+ def initialize lab, des
18
+ @label = lab
19
+ @description = des
20
+ end
21
+
22
+ def hl
23
+ (@label.length / 2.0).ceil - 1
24
+ end
25
+ end
26
+
27
+ class ArgCollection
28
+ attr_accessor :args, :arg_length, :description_width
29
+
30
+ def initialize *args
31
+ @args = []
32
+ @arg_length = 0
33
+ @description_width = 40
34
+
35
+ if !args.empty?
36
+ add_args args
37
+ end
38
+ end
39
+
40
+ def add label, description
41
+ add_arg Arg.new(label, description)
42
+ end
43
+
44
+ def add_arg ar
45
+ @args << ar
46
+ @arg_length += ar.label.length + 3
47
+ end
48
+
49
+ def add_args args
50
+ args.each do |a|
51
+ add_arg a
52
+ end
53
+ end
54
+
55
+ def draw
56
+ @args.each { |arg| print arg.label + " " }
57
+ puts ""
58
+ @args.each { |arg| print (" "*arg.hl), "┬", (" "*arg.hl), " " }
59
+ puts ""
60
+ @args.each { |arg| print (" "*arg.hl), "│", (" "*arg.hl), " " }
61
+ puts ""
62
+
63
+ r = @args.size - 1
64
+
65
+ for u in 0..r
66
+ i = @args.size - u - 1;
67
+ m = ""
68
+ for k in 0..(i-1)
69
+ m += (" "*@args[k].hl) + "│" + (" "*@args[k].hl) + " "
70
+ end
71
+ s = m + (" "*@args[i].hl)
72
+ p = (s+ "└").ljust(@arg_length , "─")
73
+ print p + ' '
74
+
75
+
76
+ t = @args[i].description
77
+ puts t.slice!(0..40)
78
+ while !t.empty?
79
+ puts s.ljust(@arg_length , " ") + ' ' + t.slice!(0..40)
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pretty_args
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: "0.5"
6
+ platform: ruby
7
+ authors:
8
+ - Artem Titoulenko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-09-05 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description: a pretty argument usage display
17
+ email: artem.titoulenko@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/pretty_args.rb
26
+ homepage: https://github.com/ArtemTitoulenko/pretty_args
27
+ licenses: []
28
+
29
+ post_install_message:
30
+ rdoc_options: []
31
+
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ requirements: []
47
+
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.8
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: make your programs arguments pretty to read and understand with a branching diagram
53
+ test_files: []
54
+