ergane 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,49 +0,0 @@
1
- module Ergane
2
- class NamedBlock
3
- def self.new(*args, &block)
4
- Class.new do
5
- args.each do |arg|
6
- attr_reader arg.to_sym
7
- end
8
-
9
- def initialize(label, args)
10
- @label = label.to_sym
11
- args.each do |arg, value|
12
- instance_variable_set("@#{args}", value)
13
- end
14
- end
15
- end
16
- end
17
- private :initialize
18
- end
19
-
20
- class SwitchDefinition < NamedBlock.new(:short, :kind, :argument, :description, :default)
21
- attr_reader :label
22
- attr_reader :short
23
- attr_reader :kind
24
- attr_reader :argument
25
- attr_reader :description
26
- attr_reader :default
27
- attr_reader :run_block
28
-
29
- def initialize(label, short: nil, argument: nil, kind: nil, description: nil, default: nil, &block)
30
- @label, @short, @argument, @kind, @description, @default = label.to_sym, short, argument, kind, description, default
31
- @run_block = block if block_given?
32
- end
33
-
34
- def attach(option_parser, command, &block)
35
- flag_arg = argument ? "=#{argument}" : ""
36
- args = []
37
- args << "-#{short}#{flag_arg}" if short
38
- args << "--#{label.to_s.gsub(/_/, '-')}#{flag_arg}"
39
- args << kind if kind
40
- args << description if description
41
-
42
- option_parser.on(*args, Proc.new { |value|
43
- command.instance_exec(value, &block) if block_given?
44
- command.instance_exec(value, &run_block) if run_block
45
- })
46
- end
47
-
48
- end
49
- end
data/lib/ergane/util.rb DELETED
@@ -1,77 +0,0 @@
1
- module Ergane
2
- module Util
3
-
4
- def self.colors
5
- # @colors = [:red, :yellow, :green, :blue, :cyan, :magenta].cycle
6
- @colors ||= [:light_red, :light_yellow, :light_green, :light_blue, :light_cyan, :light_magenta].cycle
7
- end
8
-
9
- def self.color_array(array)
10
- array.collect do |a|
11
- a.to_s.send(colors.next.to_sym).underline
12
- end
13
- end
14
-
15
- def self.color_array!(array)
16
- colors.rewind
17
- array.collect do |a|
18
- a.to_s.send(colors.next.to_sym).underline
19
- end
20
- end
21
-
22
- def self.rainbow(string, delimeter=' ')
23
- rainbow_a(string.split(delimeter)).join(delimeter)
24
- end
25
-
26
- def self.rainbow!(string, delimeter=' ')
27
- rainbow_a!(string.split(delimeter)).join(delimeter)
28
- end
29
-
30
- def self.rainbow_a(array)
31
- array.collect do |a|
32
- a.to_s.send(next_color).underline
33
- end
34
- end
35
-
36
- def self.rainbow_a!(array)
37
- rainbow_colors.rewind
38
- array.collect do |a|
39
- a.to_s.send(next_color).underline
40
- end
41
- end
42
-
43
- def self.next_color
44
- colors.next
45
- end
46
-
47
- def self.rainbow_colors
48
- @rainbow_colors = [:light_red, :light_yellow, :light_green, :light_blue, :light_cyan, :light_magenta].cycle
49
- end
50
-
51
- def self.next_rainbow_color
52
- rainbow_colors.cycle
53
- end
54
-
55
- def self.full_name
56
- @full_name ||= `finger \`whoami\` | grep Name | awk -F 'Name: ' '{print $2}'`.chomp
57
- end
58
-
59
- def self.last_name
60
- @last_name || begin
61
- split_names.last
62
- end
63
- end
64
-
65
- def self.first_name
66
- @first_name || begin
67
- split_names.first
68
- end
69
- end
70
-
71
- private
72
-
73
- def self.split_names
74
- @first_name, @last_name = ful_name.split(' ')
75
- end
76
- end
77
- end