directory_paradise 1.4.4

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.

Potentially problematic release.


This version of directory_paradise might be problematic. Click here for more details.

Files changed (31) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +213 -0
  3. data/bin/show_directory_content +7 -0
  4. data/directory_paradise.gemspec +45 -0
  5. data/doc/README.gen +185 -0
  6. data/doc/todo/todo.md +4 -0
  7. data/lib/directory_paradise/base/base.rb +195 -0
  8. data/lib/directory_paradise/base/colours.rb +196 -0
  9. data/lib/directory_paradise/constants/newline.rb +14 -0
  10. data/lib/directory_paradise/content/constants.rb +23 -0
  11. data/lib/directory_paradise/content/content.rb +682 -0
  12. data/lib/directory_paradise/project/project.rb +22 -0
  13. data/lib/directory_paradise/report/constants.rb +39 -0
  14. data/lib/directory_paradise/report/initialize.rb +75 -0
  15. data/lib/directory_paradise/report/menu.rb +329 -0
  16. data/lib/directory_paradise/report/misc.rb +675 -0
  17. data/lib/directory_paradise/report/obtain.rb +357 -0
  18. data/lib/directory_paradise/report/report.rb +527 -0
  19. data/lib/directory_paradise/report/reset.rb +174 -0
  20. data/lib/directory_paradise/requires/require_class_content.rb +7 -0
  21. data/lib/directory_paradise/requires/require_class_report.rb +7 -0
  22. data/lib/directory_paradise/requires/require_the_directory_paradise_project.rb +10 -0
  23. data/lib/directory_paradise/sdc.rb +24 -0
  24. data/lib/directory_paradise/to_human_readable/to_human_readable.rb +98 -0
  25. data/lib/directory_paradise/version/version.rb +19 -0
  26. data/lib/directory_paradise/yaml/colours_for_bytes_values.yml +14 -0
  27. data/lib/directory_paradise.rb +1 -0
  28. data/test/testing_class_content.rb +16 -0
  29. data/test/testing_class_report.rb +40 -0
  30. data/test/testing_toplevel_methods.rb +14 -0
  31. metadata +110 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 98d8042374552eb167d6a769c301a21a4bdae7bbde61f10d9294970c69e6d42d
4
+ data.tar.gz: a16bd8df8cf43b35faa3d34846a504d805dac960458c6e7f81822ace0e62a325
5
+ SHA512:
6
+ metadata.gz: 6bbaf3b5bcb77ede94cd8e0033b8185ee98b24975d2a6067a76529625dd58bf9e7ee8b1b3cb0cf0962c45bd271d987aecf98e9a4953ee465b06415f4df742493
7
+ data.tar.gz: c17b8722ad749160c9b47841ddedbbbb44102958e6917756bda6adc85cc13135ecf21294757de458d8abe961d6fc2ae06fe649f014333b38aa74dc257dbf7f44
data/README.md ADDED
@@ -0,0 +1,213 @@
1
+ # @title Directory Content
2
+ # @markup kramdown
3
+
4
+ [![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](https://www.gobolinux.org/)
5
+ [![forthebadge](http://forthebadge.com/images/badges/made-with-ruby.svg)](https://www.ruby-lang.org/en/)
6
+ [![Gem Version](https://badge.fury.io/rb/directory_paradise.svg)](https://badge.fury.io/rb/directory_paradise)
7
+
8
+ This gem was <b>last updated</b> on the <span style="color: darkblue; font-weight: bold">15.05.2022</span> (dd.mm.yyyy notation), at <span style="color: steelblue; font-weight: bold">07:13:57</span> o'clock.
9
+
10
+ <img src="https://i.imgur.com/hbGDM7i.jpg">
11
+
12
+ ## The directory_paradise gem - an introduction
13
+
14
+ The directory_paradise gem originated from the older directory_content gem.
15
+
16
+ I got tired of trying to fix bugs derived from the old code base, though,
17
+ so I decided to just start a new project altogether, while re-using the
18
+ parts of the code that works.
19
+
20
+ As I gained a bit of experience, I decided to adapt the old approach.
21
+ This will be mentioned at a later time in this document.
22
+
23
+ This small gem may be useful whenever you wish to display the content
24
+ of a (local) directory, similar to how the linux/unix program called
25
+ **ls** operates.
26
+
27
+ I needed a variant of **ls** for my ruby-shell (the **roebe-shell**),
28
+ so this project here was created years ago. Unfortunately over
29
+ the years I changed parts of the code, without properly
30
+ designing it, leading to quite some confusion as to what the
31
+ project really should do, and how it should achieve this.
32
+
33
+ Thus, this README here shall not only explain the use cases of the
34
+ project as such, but document a few internal decisions as well,
35
+ including the rationale behind having made that decision.
36
+
37
+ That way we can use the **documentation** as some form of
38
+ specification as well, and check to see that the code
39
+ adheres to this specification. This may be helpful in the
40
+ future, because I already rewrote this project several times
41
+ before already.
42
+
43
+ There are now two main classes for the **directory_paradise** project:
44
+
45
+ (1) **class Report**, which will be in the **report/** subdirectory.
46
+
47
+ This class will be responsible for displaying the content of a directory
48
+ to the user.
49
+
50
+ (2) **class Content** which will reside in the **content/** directory.
51
+
52
+ This class will be responsible for obtaining all the necessary
53
+ information to provide data to class Report. It may no longer
54
+ report anything to the user, except for debug output when we
55
+ test or modify it.
56
+
57
+ Hopefully these design choices will make it easier to maintain the
58
+ code base. In the past the old class that was similar to class
59
+ Content also displayed some information, which led to code duplication
60
+ and confusion, aka where to put new code in.
61
+
62
+ Furthermore, a new class called Base will now exist that can be used
63
+ to share code between these two classes, such return_pwd (which is
64
+ similar to Dir.pwd, but always ensures that a trailing / will be
65
+ there).
66
+
67
+ ## class Content
68
+
69
+ This is the main class of module DirectoryParadise. It will not report
70
+ anything to the user, but it will parse the entries in a given directory
71
+ and store these entries in a hash that is available via .entries?.
72
+
73
+ The method .entries? will return which entries (files, directories
74
+ or symlinks) were found in the given directory.
75
+
76
+ The method .n_entries? will return a number, indicating how many
77
+ such entries could be found.
78
+
79
+ The method .obtain_entries_from() can be used to fill up the
80
+ entries. If you also want to change the target directory,
81
+ make use of the method .set_target_directory().
82
+
83
+ The method .report() can be used to report the content. It is,
84
+ however had, not called by default for class DirectoryContent.
85
+ Note that another class, called ShowDirectoryContent, is the
86
+ one that is more apt and adjusted to displaying content.
87
+
88
+ This class is the one that should be used when you wish to display
89
+ the content of a directory. It will make use of class DirectoryContent,
90
+ so there is a **separation-of-concern**.
91
+
92
+ Note that you could also use class DirectoryContent to display
93
+ content too, via the .report() method - but this is mostly just
94
+ as a way to quickly debug something. For a more advanced display
95
+ of files and directories, use class DirectoryContent::ShowDirectoryContent
96
+ as it has been created precisely for that use case.
97
+
98
+ ## Specification for class Content - the individual entries explained
99
+
100
+ Essentially class Content has a hash that describes the content
101
+ of a directory. This subsection will explain some of the entries that
102
+ can be found in that hash, and thus may serve as some kind of
103
+ specification.
104
+
105
+ First, the path to the file or directory at hand will be the main key.
106
+ So, for example, if you have an archive called Images.tar.xz at
107
+ the directory /Depot/, then the key to the description of that
108
+ entry will be **/Depot/Images.tar.xz**. That way we always know
109
+ where class DirectoryContent 'points' at.
110
+
111
+ Now knowing this key, let's have a look at the individual entries:
112
+
113
+ :type=>"file" # keep track of the file type, e. g. file, directory or link.
114
+ :size=>47626780 # we want to know the file size too, so that we don't have to call any other method querying this again.
115
+ :is_executable=>false # is our file executable? Typically entries in /usr/bin/ will be executables
116
+ :path=>"/Depot/Images.tar.xz" # here we store the path again, to simplify querying the path.
117
+ :ascii_representation=>"-rw-r--r--" # This is mostly used to keep compatibility to GNU coreutils "ls"
118
+ :last_modified=>2021-03-09 01:20:09.432056708 +0000 # Keep track as to when this entry was last modified.
119
+ :gid=>0 # group id
120
+ :inode_number=>93857180 # its inode number
121
+ :uid=>0 # user id
122
+ :access_mode=>"644" # access mode
123
+ :name_of_owner=>"root" # name of the current owner of that entry
124
+ :name_of_group=>"root" # name of the current group of that entry
125
+
126
+ ## Behaviour on missing symlinks
127
+
128
+ If a missing symlink (that is, the target to which this symlink points
129
+ to does not exist) is encountered, then class ShowDirectoryContent
130
+ will either ignore this, or display to the user that a symlink is
131
+ missing. Additionally it may stop altogether when a missing
132
+ symlink is discovered. That way the user is sort of forced to
133
+ fix this issue - I needed this once on **GoboLinux**, which is why
134
+ this functionality had to exist.
135
+
136
+ This is handled internally via the method call **stop_on_missing_symlink?**.
137
+
138
+ The next subsection deals with class DirectoryParadise::Report, which
139
+ is the main class when you wish to display the content of a directory.
140
+
141
+ ## Display only directory in the current working directory
142
+
143
+ If you only wish to display all directories in the current
144
+ working directory then you can use the method called
145
+ <b>.only_directories</b>, or, from the commandline:
146
+
147
+ sdc --only-directories
148
+
149
+ ## Do not show the header
150
+
151
+ By default, class DirectoryParadise::Report will show a header on
152
+ top, to explain some of the options.
153
+
154
+ This may not always be wanted, so a commandline option exists
155
+ to NOT show the header.
156
+
157
+ Example for this:
158
+
159
+ sdc --noheader
160
+ sdc --no-header
161
+
162
+ This is more similar to how "ls" works by default too, by the
163
+ way.
164
+
165
+ ## Show hidden files
166
+
167
+ This should show hidden files aka those with a leading '.':
168
+
169
+ sdc --show
170
+
171
+ Several aliases exist to this. Have a look at **menu.rb** to
172
+ see all aliases to it, at **directory_paradise/report/menu.rb**.
173
+
174
+ # Customising colours via the yaml file called colours_for_bytes_values.yml
175
+
176
+ You can customize the existing colours for KB, MB and GB values,
177
+ via the yaml file called **colours_for_bytes_values.yml**. Currently
178
+ only a few colours are supported, though. This may be extended one
179
+ day, if people want to use other colours by default for the KB,
180
+ MB and GB entries.
181
+
182
+ Since as of **January 2022** the code will also check whether the
183
+ colour names are correct. I had a typo called **mediumpurples**
184
+ which did not exist, leading to another project break. This
185
+ is bad, so now the directory_paradise gem will verify whether
186
+ the colours exist or not.
187
+
188
+
189
+ ## Contact information
190
+
191
+ If your creative mind has ideas and specific suggestions to make this
192
+ gem more useful in general, feel free to drop me an email at any
193
+ time, via:
194
+
195
+ shevy@inbox.lt
196
+
197
+ Before that email I used an email account at Google gmail, but in **2021** I
198
+ decided to slowly abandon gmail for various reasons. In part this is because
199
+ the UI annoys me (on non-chrome browser loading takes too long), but also
200
+ because of Google's attempt to establish mass surveillance via its
201
+ federated cohorts sniffing (FLoC). I do not know what happened at Google,
202
+ but enough is enough - there is only so much you can take while supporting
203
+ greed. When it comes to data mining done by private groups, ultimately
204
+ the user became the product.
205
+
206
+ Do keep in mind that responding to emails may take some time,
207
+ depending on the amount of work I may have at that moment, due
208
+ to reallife time constraints. I will, however had, read feedback
209
+ eventually. Patches and code changes are welcome too, of course,
210
+ as long as they are in the spirit of the project at hand, e. g.
211
+ fitting to the general theme. For this I may make use of github
212
+ as a discussion site, but this has a low priority right now.
213
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'directory_paradise'
6
+
7
+ DirectoryParadise.show(ARGV)
@@ -0,0 +1,45 @@
1
+ require 'directory_paradise/version/version.rb'
2
+ require 'roebe/toplevel_methods/misc.rb'
3
+
4
+ Gem::Specification.new { |s|
5
+
6
+ s.name = 'directory_paradise'
7
+ s.version = DirectoryParadise::VERSION
8
+ s.date = Time.now.strftime('%Y-%m-%d')
9
+
10
+ DESCRIPTION = <<-EOF
11
+
12
+ This class will display the content of a directory. It
13
+ can also give back a data-object that describes the
14
+ content of a directory, e. g. all files or directories
15
+ found in that directory.
16
+
17
+ The class aims to function somewhat similar to the
18
+ UNIX/coreutils program called "ls".
19
+
20
+ The latest version now comes with a test/ directory.
21
+
22
+ The method apply_filter() was added, so now we can
23
+ filter almost like "ls *foo*" could filter.
24
+
25
+ As of version 1.0.3, showing the Index is optional.
26
+
27
+ EOF
28
+
29
+ s.summary = DESCRIPTION
30
+ s.description = DESCRIPTION
31
+
32
+ s.authors = ['Robert A. Heiler']
33
+ s.email = Roebe.email?
34
+ s.files = Dir['**/*']
35
+ s.homepage = 'https://rubygems.org/gems/directory_paradise'
36
+ s.licenses = 'MIT'
37
+
38
+ s.required_ruby_version = '>= '+Roebe.third_most_stable_version_of_ruby
39
+ s.required_rubygems_version = '>= '+Gem::VERSION
40
+ s.rubygems_version = '>= '+Gem::VERSION
41
+
42
+ s.add_dependency 'colours'
43
+ s.add_dependency 'opn'
44
+
45
+ }
data/doc/README.gen ADDED
@@ -0,0 +1,185 @@
1
+ # @title Directory Content
2
+ # @markup kramdown
3
+
4
+ ADD_RUBY_BADGE
5
+ ADD_TIME_STAMP
6
+
7
+ <img src="https://i.imgur.com/hbGDM7i.jpg">
8
+
9
+ ## The directory_paradise gem - an introduction
10
+
11
+ The directory_paradise gem originated from the older directory_content gem.
12
+
13
+ I got tired of trying to fix bugs derived from the old code base, though,
14
+ so I decided to just start a new project altogether, while re-using the
15
+ parts of the code that works.
16
+
17
+ As I gained a bit of experience, I decided to adapt the old approach.
18
+ This will be mentioned at a later time in this document.
19
+
20
+ This small gem may be useful whenever you wish to display the content
21
+ of a (local) directory, similar to how the linux/unix program called
22
+ **ls** operates.
23
+
24
+ I needed a variant of **ls** for my ruby-shell (the **roebe-shell**),
25
+ so this project here was created years ago. Unfortunately over
26
+ the years I changed parts of the code, without properly
27
+ designing it, leading to quite some confusion as to what the
28
+ project really should do, and how it should achieve this.
29
+
30
+ Thus, this README here shall not only explain the use cases of the
31
+ project as such, but document a few internal decisions as well,
32
+ including the rationale behind having made that decision.
33
+
34
+ That way we can use the **documentation** as some form of
35
+ specification as well, and check to see that the code
36
+ adheres to this specification. This may be helpful in the
37
+ future, because I already rewrote this project several times
38
+ before already.
39
+
40
+ There are now two main classes for the **directory_paradise** project:
41
+
42
+ (1) **class Report**, which will be in the **report/** subdirectory.
43
+
44
+ This class will be responsible for displaying the content of a directory
45
+ to the user.
46
+
47
+ (2) **class Content** which will reside in the **content/** directory.
48
+
49
+ This class will be responsible for obtaining all the necessary
50
+ information to provide data to class Report. It may no longer
51
+ report anything to the user, except for debug output when we
52
+ test or modify it.
53
+
54
+ Hopefully these design choices will make it easier to maintain the
55
+ code base. In the past the old class that was similar to class
56
+ Content also displayed some information, which led to code duplication
57
+ and confusion, aka where to put new code in.
58
+
59
+ Furthermore, a new class called Base will now exist that can be used
60
+ to share code between these two classes, such return_pwd (which is
61
+ similar to Dir.pwd, but always ensures that a trailing / will be
62
+ there).
63
+
64
+ ## class Content
65
+
66
+ This is the main class of module DirectoryParadise. It will not report
67
+ anything to the user, but it will parse the entries in a given directory
68
+ and store these entries in a hash that is available via .entries?.
69
+
70
+ The method .entries? will return which entries (files, directories
71
+ or symlinks) were found in the given directory.
72
+
73
+ The method .n_entries? will return a number, indicating how many
74
+ such entries could be found.
75
+
76
+ The method .obtain_entries_from() can be used to fill up the
77
+ entries. If you also want to change the target directory,
78
+ make use of the method .set_target_directory().
79
+
80
+ The method .report() can be used to report the content. It is,
81
+ however had, not called by default for class DirectoryContent.
82
+ Note that another class, called ShowDirectoryContent, is the
83
+ one that is more apt and adjusted to displaying content.
84
+
85
+ This class is the one that should be used when you wish to display
86
+ the content of a directory. It will make use of class DirectoryContent,
87
+ so there is a **separation-of-concern**.
88
+
89
+ Note that you could also use class DirectoryContent to display
90
+ content too, via the .report() method - but this is mostly just
91
+ as a way to quickly debug something. For a more advanced display
92
+ of files and directories, use class DirectoryContent::ShowDirectoryContent
93
+ as it has been created precisely for that use case.
94
+
95
+ ## Specification for class Content - the individual entries explained
96
+
97
+ Essentially class Content has a hash that describes the content
98
+ of a directory. This subsection will explain some of the entries that
99
+ can be found in that hash, and thus may serve as some kind of
100
+ specification.
101
+
102
+ First, the path to the file or directory at hand will be the main key.
103
+ So, for example, if you have an archive called Images.tar.xz at
104
+ the directory /Depot/, then the key to the description of that
105
+ entry will be **/Depot/Images.tar.xz**. That way we always know
106
+ where class DirectoryContent 'points' at.
107
+
108
+ Now knowing this key, let's have a look at the individual entries:
109
+
110
+ :type=>"file" # keep track of the file type, e. g. file, directory or link.
111
+ :size=>47626780 # we want to know the file size too, so that we don't have to call any other method querying this again.
112
+ :is_executable=>false # is our file executable? Typically entries in /usr/bin/ will be executables
113
+ :path=>"/Depot/Images.tar.xz" # here we store the path again, to simplify querying the path.
114
+ :ascii_representation=>"-rw-r--r--" # This is mostly used to keep compatibility to GNU coreutils "ls"
115
+ :last_modified=>2021-03-09 01:20:09.432056708 +0000 # Keep track as to when this entry was last modified.
116
+ :gid=>0 # group id
117
+ :inode_number=>93857180 # its inode number
118
+ :uid=>0 # user id
119
+ :access_mode=>"644" # access mode
120
+ :name_of_owner=>"root" # name of the current owner of that entry
121
+ :name_of_group=>"root" # name of the current group of that entry
122
+
123
+ ## Behaviour on missing symlinks
124
+
125
+ If a missing symlink (that is, the target to which this symlink points
126
+ to does not exist) is encountered, then class ShowDirectoryContent
127
+ will either ignore this, or display to the user that a symlink is
128
+ missing. Additionally it may stop altogether when a missing
129
+ symlink is discovered. That way the user is sort of forced to
130
+ fix this issue - I needed this once on **GoboLinux**, which is why
131
+ this functionality had to exist.
132
+
133
+ This is handled internally via the method call **stop_on_missing_symlink?**.
134
+
135
+ The next subsection deals with class DirectoryParadise::Report, which
136
+ is the main class when you wish to display the content of a directory.
137
+
138
+ ## Display only directory in the current working directory
139
+
140
+ If you only wish to display all directories in the current
141
+ working directory then you can use the method called
142
+ <b>.only_directories</b>, or, from the commandline:
143
+
144
+ sdc --only-directories
145
+
146
+ ## Do not show the header
147
+
148
+ By default, class DirectoryParadise::Report will show a header on
149
+ top, to explain some of the options.
150
+
151
+ This may not always be wanted, so a commandline option exists
152
+ to NOT show the header.
153
+
154
+ Example for this:
155
+
156
+ sdc --noheader
157
+ sdc --no-header
158
+
159
+ This is more similar to how "ls" works by default too, by the
160
+ way.
161
+
162
+ ## Show hidden files
163
+
164
+ This should show hidden files aka those with a leading '.':
165
+
166
+ sdc --show
167
+
168
+ Several aliases exist to this. Have a look at **menu.rb** to
169
+ see all aliases to it, at **directory_paradise/report/menu.rb**.
170
+
171
+ # Customising colours via the yaml file called colours_for_bytes_values.yml
172
+
173
+ You can customize the existing colours for KB, MB and GB values,
174
+ via the yaml file called **colours_for_bytes_values.yml**. Currently
175
+ only a few colours are supported, though. This may be extended one
176
+ day, if people want to use other colours by default for the KB,
177
+ MB and GB entries.
178
+
179
+ Since as of **January 2022** the code will also check whether the
180
+ colour names are correct. I had a typo called **mediumpurples**
181
+ which did not exist, leading to another project break. This
182
+ is bad, so now the directory_paradise gem will verify whether
183
+ the colours exist or not.
184
+
185
+ ADD_CONTACT_INFORMATION
data/doc/todo/todo.md ADDED
@@ -0,0 +1,4 @@
1
+ (1) At the display of the file size,
2
+ consider using:
3
+
4
+ to_human_readable(file_size)
@@ -0,0 +1,195 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === DirectoryParadise::Base
6
+ #
7
+ # Usage example:
8
+ #
9
+ # DirectoryParadise::Base.new(ARGV)
10
+ #
11
+ # =========================================================================== #
12
+ # require 'directory_paradise/base/base.rb'
13
+ # =========================================================================== #
14
+ require 'directory_paradise/constants/newline.rb'
15
+
16
+ module DirectoryParadise
17
+
18
+ class Base
19
+
20
+ alias e puts
21
+ alias ee print
22
+
23
+ require 'directory_paradise/base/colours.rb'
24
+ require 'directory_paradise/to_human_readable/to_human_readable.rb'
25
+
26
+ # ========================================================================= #
27
+ # === is_on_windows?
28
+ # ========================================================================= #
29
+ def is_on_windows?
30
+ if RUBY_PLATFORM.include?('win') or # if on windows.
31
+ RUBY_PLATFORM.include?('mingw')
32
+ return true
33
+ end
34
+ return false # ← Otherwise we are evidently NOT on windows, if we reach this point here.
35
+ end
36
+
37
+ # ========================================================================= #
38
+ # === rds
39
+ # ========================================================================= #
40
+ def rds(i)
41
+ i.squeeze '/'
42
+ end
43
+
44
+ # ========================================================================= #
45
+ # === register_sigint
46
+ # ========================================================================= #
47
+ def register_sigint
48
+ Signal.trap('SIGINT') { exit }
49
+ end
50
+
51
+ # ========================================================================= #
52
+ # === return_chmod_value_of_this_file
53
+ # ========================================================================= #
54
+ def return_chmod_value_of_this_file(i)
55
+ if File.exist? i
56
+ File.stat(i).mode.to_s(8).split('')[-4..-1].join # => "0755"
57
+ else
58
+ '0000'
59
+ end
60
+ end
61
+
62
+ # ========================================================================= #
63
+ # === set_commandline_arguments
64
+ # ========================================================================= #
65
+ def set_commandline_arguments(i = '')
66
+ i = [i].flatten.compact
67
+ @commandline_arguments = i
68
+ end
69
+
70
+ # ========================================================================= #
71
+ # === commandline_arguments?
72
+ # ========================================================================= #
73
+ def commandline_arguments?
74
+ @commandline_arguments
75
+ end
76
+
77
+ # ========================================================================= #
78
+ # === commandline_arguments_starting_with_two_hyphens?
79
+ # ========================================================================= #
80
+ def commandline_arguments_starting_with_two_hyphens?
81
+ @commandline_arguments.select {|entry| entry.start_with? '--' }
82
+ end
83
+
84
+ # ========================================================================= #
85
+ # === return_non_hyphen_entries_from
86
+ # ========================================================================= #
87
+ def return_non_hyphen_entries_from(i)
88
+ if i.is_a? Array
89
+ i.select {|entry| !entry.start_with?('--') }
90
+ else
91
+ nil
92
+ end
93
+ end
94
+
95
+ # ========================================================================= #
96
+ # === first_argument?
97
+ # ========================================================================= #
98
+ def first_argument?
99
+ @commandline_arguments.first
100
+ end; alias first? first_argument? # === first?
101
+
102
+ # ========================================================================= #
103
+ # === return_pwd
104
+ # ========================================================================= #
105
+ def return_pwd
106
+ "#{Dir.pwd}/".squeeze('/')
107
+ end
108
+
109
+ # ========================================================================= #
110
+ # === eliner
111
+ # ========================================================================= #
112
+ def eliner
113
+ e '―' * 80
114
+ end
115
+
116
+ # ========================================================================= #
117
+ # === liner
118
+ # ========================================================================= #
119
+ def liner # adds a line.
120
+ if block_given?
121
+ liner
122
+ yield
123
+ end
124
+ return ('*' * 80)+N
125
+ end
126
+
127
+ # ========================================================================= #
128
+ # === return_owner
129
+ #
130
+ # This method determines the owner of a file or directory.
131
+ # ========================================================================= #
132
+ def return_owner(
133
+ of_this_uid
134
+ )
135
+ _ = ''.dup # The _ is the return value.
136
+ # ======================================================================= #
137
+ # The next block of code can fail on windows, hence why this is
138
+ # wrapped carefully.
139
+ # ======================================================================= #
140
+ begin
141
+ if of_this_uid.is_a? String
142
+ of_this_uid = of_this_uid.to_i
143
+ end
144
+ # ===================================================================== #
145
+ # The next line must be rescued because the filesystem may be faulty.
146
+ # ===================================================================== #
147
+ begin
148
+ result_from_getpwuid = Etc.getpwuid(of_this_uid)
149
+ rescue TypeError
150
+ result_from_getpwuid = false
151
+ end
152
+ if result_from_getpwuid
153
+ _ << result_from_getpwuid.name
154
+ else
155
+ _ << '(unknown)'
156
+ end
157
+ rescue ArgumentError
158
+ _ << '(unknown)'
159
+ rescue Errno::ENOENT
160
+ _ << '(missing)'
161
+ end
162
+ _ # Return it here.
163
+ end; alias owner? return_owner # === owner?
164
+
165
+ # ========================================================================= #
166
+ # === return_assumed_modification_time
167
+ # ========================================================================= #
168
+ def return_assumed_modification_time(i)
169
+ month = Date::MONTHNAMES[i.month][0,3] # => "Jun"
170
+ "#{month} #{i.day.to_s.rjust(2)}"
171
+ end
172
+
173
+ # ========================================================================= #
174
+ # === clear_the_internal_hash
175
+ # ========================================================================= #
176
+ def clear_the_internal_hash
177
+ @internal_hash.clear
178
+ end; alias clear clear_the_internal_hash # === clear
179
+
180
+ # ========================================================================= #
181
+ # === to_human_readable
182
+ #
183
+ # The strange thing is, in bash, we seem to round up.
184
+ #
185
+ # How many MB (megabyte) are in 1 GB (gigabyte)? 1024.
186
+ # ========================================================================= #
187
+ def to_human_readable(i)
188
+ return DirectoryParadise.to_human_readable(i)
189
+ end
190
+
191
+ end; end
192
+
193
+ if __FILE__ == $PROGRAM_NAME
194
+ DirectoryParadise::Base.new(ARGV)
195
+ end # base.rb