bash_help 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e49057a292dc8396e33f338d215988ccc2aeaae7b8214af813db058e75e655c0
4
- data.tar.gz: c9e7d9141ea7fad0b09f5ff1f7b54a1a486cc3a1bd3f70e4225a97a5c8be8683
3
+ metadata.gz: 5ba51a95971f3b6ec99e21420faa25c89035028aee10cc4ce50914a983a326af
4
+ data.tar.gz: 253f33b13708c8bb6b963b61d238763799e8597a70e1f8ab6cf46f6a07c050e0
5
5
  SHA512:
6
- metadata.gz: 7bef055dec56ec0c6130158eb66d85b8a312003f8ab1338d84ca3034106b009bcb21b0782cf492646e118314dc7e49f7d731b5ff7923794d02f1b6abd63adca3
7
- data.tar.gz: c5835b163e9e01c0e11fb8cf3a6c07650e77dd65c24e3e5007f4c4cfbcacb49e8a08d27864fa9db037460a63f5140245ebf1e55987e1d92c429d8c2c0c7dabde
6
+ metadata.gz: 2292d7a6d5a61723f63bd4ce3e4a36905ef7e7f5d54e36645f5bbccf42b5ed8dc7b050fd221845810701ed918ead3599b6dacda6d0cabcaab3cadd7657300954
7
+ data.tar.gz: c4719b8257130483286d0a048eab33e063ffbd2dad6edb5d35d890cd98e6f358b13d61a0e7861fc157f69671ccff5589022c83de8e9a3066bc09bce0570db7cb
data/lib/bash_help.rb CHANGED
@@ -7,3 +7,5 @@
7
7
  require_relative 'hello_module.rb'
8
8
  require_relative 'bash_standins.rb'
9
9
  require_relative 'general_helpers.rb'
10
+ require_relative 'drawing.rb'
11
+ require_relative 'compile.rb'
data/lib/compile.rb ADDED
@@ -0,0 +1,42 @@
1
+ # helper functions for compilation, used primarily for quick ruby build scripts.
2
+
3
+ require_relative 'drawing.rb'
4
+ require_relative 'general_helpers.rb'
5
+
6
+ ## C compiler helpers:
7
+ def gcc_compile(files, project_name, extra_flags = '', override_flags = false)
8
+ line
9
+
10
+ if files.empty?
11
+ puts 'No files to compile'
12
+ return
13
+ end
14
+
15
+ if project_name.empty?
16
+ puts 'No project name given'
17
+ return
18
+ end
19
+
20
+ puts "Compiling #{files} into #{project_name}..."
21
+
22
+ ignore_header_warnings = '-Wno-builtin-declaration-mismatch -Wno-implicit-function-declaration'
23
+
24
+ default_flags = ['-g', ignore_header_warnings].join(' ')
25
+ flags = [default_flags, extra_flags].join(' ')
26
+
27
+ flags = extra_flags if override_flags
28
+
29
+ puts "Flags: #{flags}"
30
+
31
+ command = "gcc -o #{project_name} #{files} #{flags}"
32
+
33
+ # exit if the compilation fails.
34
+ safe_system command
35
+
36
+ puts "Compiled #{project_name}"
37
+ puts "Running..."
38
+
39
+ line
40
+
41
+ safe_system "./#{project_name}"
42
+ end
data/lib/drawing.rb ADDED
@@ -0,0 +1,116 @@
1
+ # text drawing helper functions.
2
+
3
+ def line
4
+ puts '-' * 80
5
+ end
6
+
7
+ def box_text(text)
8
+ length = text.length + 4
9
+ puts '+' + '-' * length + '+'
10
+ puts "| " + text + " |"
11
+ puts '+' + '-' * length + '+'
12
+ end
13
+
14
+ def double_box_text(text)
15
+ length = text.length + 6
16
+ puts '+' + '=' * length + '+'
17
+ puts "|| " + text + " ||"
18
+ puts '+' + '=' * length + '+'
19
+ end
20
+
21
+ def center_text(text)
22
+ total_length = 80
23
+ text_length = text.length
24
+ leading_space = (total_length - text_length) / 2
25
+ puts ' ' * leading_space + text
26
+ end
27
+
28
+ def right_align_text(text)
29
+ total_length = 80
30
+ text_length = text.length
31
+ leading_space = total_length - text_length
32
+ puts ' ' * leading_space + text
33
+ end
34
+
35
+ def draw_horizontal_line(length)
36
+ puts '-' * length
37
+ end
38
+
39
+ def draw_vertical_line(length)
40
+ length.times { puts '|' }
41
+ end
42
+
43
+ def star_text(text)
44
+ length = text.length + 6
45
+ puts '*' * length
46
+ puts "** " + text + " **"
47
+ puts '*' * length
48
+ end
49
+
50
+ def triangle_text(text)
51
+ length = text.length + 2
52
+ length.times { |i| puts ' ' * (length - i) + text[0..i] }
53
+ end
54
+
55
+ def pyramid_text(text)
56
+ length = text.length
57
+ (length / 2 + 1).times do |i|
58
+ puts ' ' * (length - i) + text[0..(2*i)] + ' ' * (length - i)
59
+ end
60
+ end
61
+
62
+ # Testing function
63
+ def test_all_drawing_methods
64
+ # Test the line function
65
+ puts "Testing the line function:"
66
+ line
67
+ puts "\n"
68
+
69
+ # Test the box_text function
70
+ puts "Testing the box_text function:"
71
+ box_text("Test text")
72
+ puts "\n"
73
+
74
+ # Test the double_box_text function
75
+ puts "Testing the double_box_text function:"
76
+ double_box_text("Test text")
77
+ puts "\n"
78
+
79
+ # Test the center_text function
80
+ puts "Testing the center_text function:"
81
+ center_text("Test text")
82
+ puts "\n"
83
+
84
+ # Test the right_align_text function
85
+ puts "Testing the right_align_text function:"
86
+ right_align_text("Test text")
87
+ puts "\n"
88
+
89
+ # Test the draw_horizontal_line function
90
+ puts "Testing the draw_horizontal_line function:"
91
+ draw_horizontal_line(10)
92
+ puts "\n"
93
+
94
+ # Test the draw_vertical_line function
95
+ puts "Testing the draw_vertical_line function:"
96
+ draw_vertical_line(10)
97
+ puts "\n"
98
+
99
+ # Test the star_text function
100
+ puts "Testing the star_text function:"
101
+ star_text("Test text")
102
+ puts "\n"
103
+
104
+ # Test the triangle_text function
105
+ puts "Testing the triangle_text function:"
106
+ triangle_text("Test text")
107
+ puts "\n"
108
+
109
+ # Test the pyramid_text function
110
+ puts "Testing the pyramid_text function:"
111
+ pyramid_text("Test text")
112
+ puts "\n"
113
+ end
114
+
115
+ # Run the testing function
116
+ test_all_drawing_methods
@@ -35,9 +35,25 @@ def print_method_sig(method_name)
35
35
  end
36
36
 
37
37
  # function usage string, with a custom string param that formats it for you.
38
- def usage(method_name, custom_usage_string)
38
+ def usage(method_name, custom_usage_string, should_exit = true)
39
39
  puts "Usage for #{method_name}:"
40
40
  print_method_sig(method_name)
41
41
  puts custom_usage_string
42
- exit
42
+ if should_exit
43
+ exit
44
+ end
45
+ end
46
+
47
+ # require every file in a directory.
48
+ def require_dir(directory_path)
49
+ # Get an array of all files in the directory
50
+ script_files = Dir.glob(File.join(directory_path, '*.rb'))
51
+
52
+ # Iterate over each script file
53
+ script_files.each do |script_file|
54
+ # Require or load the script file
55
+ require script_file
56
+ # Or if you want to load instead of requiring:
57
+ # load script_file
58
+ end
43
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bash_help
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zack Fisher
@@ -18,6 +18,8 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - lib/bash_help.rb
20
20
  - lib/bash_standins.rb
21
+ - lib/compile.rb
22
+ - lib/drawing.rb
21
23
  - lib/general_helpers.rb
22
24
  - lib/hello_module.rb
23
25
  homepage: https://github.com/zack-fisher