Class: ClassDocuShower
- Inherits:
-
Object
- Object
- ClassDocuShower
- Includes:
- Colours
- Defined in:
- lib/class_docu_shower/colours.rb,
lib/class_docu_shower/version/version.rb,
lib/class_docu_shower/class_docu_shower.rb
Overview
ClassDocuShower.new
Constant Summary collapse
- VERSION =
#
ClassDocuShower::VERSION
#
'1.0.21'
- N =
"\n"
- DEFAULT_FILE =
#
DEFAULT_FILE
#
'/Users/x/DATA/PROGRAMMING_LANGUAGES/RUBY/src/tools/show_available_users.rb'
- FORBIDDEN_CHARACTERS =
#
FORBIDDEN_CHARACTERS
#
'# ===='
- ENCODING_TO_USE =
#
ENCODING_TO_USE
#
'ISO-8859-1'
Class Method Summary collapse
-
.[](i) ⇒ Object
# === ClassDocuShower[] ========================================================================= #.
Instance Method Summary collapse
-
#be_silent ⇒ Object
# === be_silent ========================================================================= #.
-
#be_verbose ⇒ Object
# === be_verbose ========================================================================= #.
-
#file? ⇒ Boolean
# === file? ========================================================================= #.
-
#files? ⇒ Boolean
(also: #files)
# === files? ========================================================================= #.
-
#initialize(i = nil, run_already = true) ⇒ ClassDocuShower
constructor
# === initialize.
-
#lightblue(i) ⇒ Object
# === lightblue ========================================================================= #.
-
#orange(i) ⇒ Object
# === orange ========================================================================= #.
-
#process ⇒ Object
# === process.
-
#process_dataset ⇒ Object
# === process_dataset ========================================================================= #.
-
#read_in_file(this_file = @file) ⇒ Object
# === read_in_file.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#reset_usher_object ⇒ Object
# === reset_usher_object ========================================================================= #.
-
#result? ⇒ Boolean
# === result? ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#set_files(i = DEFAULT_FILE) ⇒ Object
# === set_files ========================================================================= #.
-
#sfile(i = '') ⇒ Object
# === sfile ========================================================================= #.
-
#show_file_header(i) ⇒ Object
# === show_file_header.
-
#show_result ⇒ Object
# === show_result ========================================================================= #.
-
#show_the_result ⇒ Object
# === show_the_result ========================================================================= #.
-
#slateblue(i) ⇒ Object
# === slateblue ========================================================================= #.
-
#use_colours? ⇒ Boolean
# === use_colours? ========================================================================= #.
Constructor Details
#initialize(i = nil, run_already = true) ⇒ ClassDocuShower
#
initialize
The first argument should be a .rb file.
The second argument can be :silent, in which case we will be silent rather than verbose.
#
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 83 84 85 86 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 56 def initialize( i = nil, run_already = true ) be_silent reset set_files(i) if run_already.is_a? Hash # Intercept hash here. if run_already.has_key? :verbose @be_verbose = run_already[:verbose] run_already = true end else case run_already when :silent be_silent run_already = true when :no_colours @use_colours = false run_already = true end end if block_given? yielded = yield case yielded when :do_not_report_the_filename @report_the_filename = false end end run if run_already end |
Class Method Details
.[](i) ⇒ Object
#
ClassDocuShower[]
#
282 283 284 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 282 def self.[](i) ClassDocuShower.new(i) end |
Instance Method Details
#be_silent ⇒ Object
#
be_silent
#
123 124 125 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 123 def be_silent @be_verbose = false end |
#be_verbose ⇒ Object
#
be_verbose
#
116 117 118 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 116 def be_verbose @be_verbose = true end |
#file? ⇒ Boolean
#
file?
#
130 131 132 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 130 def file? @file.to_s end |
#files? ⇒ Boolean Also known as: files
#
files?
#
191 192 193 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 191 def files? @files end |
#lightblue(i) ⇒ Object
#
lightblue
#
26 27 28 |
# File 'lib/class_docu_shower/colours.rb', line 26 def lightblue(i) ::Colours.lightblue(i) end |
#orange(i) ⇒ Object
#
orange
#
12 13 14 |
# File 'lib/class_docu_shower/colours.rb', line 12 def orange(i) ::Colours.orange(i) end |
#process ⇒ Object
#
process
This method contains the in-class logic.
#
208 209 210 211 212 213 214 215 216 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 208 def process @files.each {|file| show_file_header(file) read_in_file(file) process_dataset show_result e } end |
#process_dataset ⇒ Object
#
process_dataset
#
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 221 def process_dataset reset_usher_object if @data @data.each {|entry| # @data is an Array. if entry.include? FORBIDDEN_CHARACTERS # Reject leading '# ===' parts. @usher.toggle if @usher else # ================================================================= # # Else add the entry. We should not use .lstrip on it because # that way we can preserve the original indent. # ================================================================= # entry.delete!('#') # .lstrip if use_colours? and Object.const_defined?(:Colours) if entry.start_with? ' ===' entry = orange(entry) elsif entry.include? 'Usage examples:' entry = lightblue(entry) end end @usher << entry if @usher end } @result = @usher._ if @usher end end |
#read_in_file(this_file = @file) ⇒ Object
#
read_in_file
We determine @data here.
#
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 153 def read_in_file(this_file = @file) if File.exist? this_file @data = File.readlines(this_file, :encoding => ENCODING_TO_USE) else # We should report. result = 'We could not find a file at '+sfile(this_file)+',' result = Colours.remove_colours(result) unless use_colours? opn; e result result = 'thus can not check whether it has an documentation.' result = Colours.remove_colours(result) unless use_colours? opn; e result end end |
#reset ⇒ Object
#
reset (reset tag)
#
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 91 def reset @data = nil if Object.const_defined? :Usher @usher = Usher.new else @usher = nil end @result = nil @use_colours = true @report_the_filename = true end |
#reset_usher_object ⇒ Object
#
reset_usher_object
#
106 107 108 109 110 111 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 106 def reset_usher_object if @usher @usher.reset @usher.allow_n_changes = 1 end end |
#result? ⇒ Boolean
#
result?
#
169 170 171 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 169 def result? @result end |
#run ⇒ Object
#
run (run tag)
#
275 276 277 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 275 def run process end |
#set_files(i = DEFAULT_FILE) ⇒ Object
#
set_files
#
250 251 252 253 254 255 256 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 250 def set_files(i = DEFAULT_FILE) i = DEFAULT_FILE if i.nil? # i = i.to_s.dup if i i = [i] unless i.is_a? Array # Must always be an Array. i.flatten! # But keep it flattened. @files = i end |
#sfile(i = '') ⇒ Object
#
sfile
#
198 199 200 201 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 198 def sfile(i = '') i = Colours.sfile(i) if use_colours? return i end |
#show_file_header(i) ⇒ Object
#
show_file_header
This method will show the header, with an introduction like “From file bla”.
#
264 265 266 267 268 269 270 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 264 def show_file_header(i) if @report_the_filename# result = 'From file '+sfile(i)+':'+N+N result = Colours.remove_colours(result) unless use_colours? e result end end |
#show_result ⇒ Object
#
show_result
#
176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 176 def show_result if @be_verbose # We will be chatty here, aka, verbose. result = 'From the file '+sfile(file?)+' we ' result = Colours.remove_colours(result) unless use_colours? opn; e result result = 'can show this result:' result = Colours.remove_colours(result) unless use_colours? opn; e result end show_the_result end |
#show_the_result ⇒ Object
#
show_the_result
#
137 138 139 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 137 def show_the_result e @result if result? end |
#slateblue(i) ⇒ Object
#
slateblue
#
19 20 21 |
# File 'lib/class_docu_shower/colours.rb', line 19 def slateblue(i) ::Colours.slateblue(i) end |
#use_colours? ⇒ Boolean
#
use_colours?
#
144 145 146 |
# File 'lib/class_docu_shower/class_docu_shower.rb', line 144 def use_colours? @use_colours end |