Class: Cyberweb::AllCssClasses
- Inherits:
-
Object
- Object
- Cyberweb::AllCssClasses
- Defined in:
- lib/cyberweb/standalone_classes/all_css_classes.rb
Overview
Cyberweb::AllCssClasses
Constant Summary collapse
- N =
#
N
#
"\n"
- HOME_DIRECTORY_OF_THE_USER_X =
#
HOME_DIRECTORY_OF_THE_USER_X
#
'/home/x/'
- CSS_DIR =
#
CSS_DIR
#
"#{HOME_DIRECTORY_OF_THE_USER_X}data/cascading_style_sheets/"
- ARRAY_IGNORE_THESE =
#
ARRAY_IGNORE_THESE
#
%w( { } )
Instance Attribute Summary collapse
-
#this_css_file ⇒ Object
readonly
Returns the value of attribute this_css_file.
Class Method Summary collapse
-
.[](i) ⇒ Object
# === AllCssClasses[] ========================================================================= #.
Instance Method Summary collapse
-
#append_to_main_array(i) ⇒ Object
# === append_to_main_array ========================================================================= #.
-
#dataset? ⇒ Boolean
(also: #dataset)
# === dataset? ========================================================================= #.
-
#fetch_data(from = @this_css_file) ⇒ Object
# === fetch_data.
-
#found? ⇒ Boolean
# === found?.
-
#include?(*array) ⇒ Boolean
# === include?.
-
#initialize(this_css_file = CSS_DIR, run_already = true) ⇒ AllCssClasses
constructor
# === initialize ========================================================================= #.
-
#output_result ⇒ Object
(also: #report)
# === output_result ========================================================================= #.
-
#readlines(from, use_this_encoding = ::Cyberweb::Encoding::ENCODING_TO_USE) ⇒ Object
# === readlines ========================================================================= #.
-
#reset ⇒ Object
# === reset ========================================================================= #.
-
#result ⇒ Object
# === result ========================================================================= #.
-
#run ⇒ Object
# === run ========================================================================= #.
-
#set_this_css_file(i) ⇒ Object
# === set_this_css_file ========================================================================= #.
-
#test(i) ⇒ Object
# === test ========================================================================= #.
Constructor Details
#initialize(this_css_file = CSS_DIR, run_already = true) ⇒ AllCssClasses
#
initialize
#
44 45 46 47 48 49 50 51 |
# File 'lib/cyberweb/standalone_classes/all_css_classes.rb', line 44 def initialize( this_css_file = CSS_DIR, run_already = true ) reset set_this_css_file(this_css_file) run if run_already end |
Instance Attribute Details
#this_css_file ⇒ Object (readonly)
Returns the value of attribute this_css_file.
17 18 19 |
# File 'lib/cyberweb/standalone_classes/all_css_classes.rb', line 17 def this_css_file @this_css_file end |
Class Method Details
Instance Method Details
#append_to_main_array(i) ⇒ Object
#
append_to_main_array
#
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/cyberweb/standalone_classes/all_css_classes.rb', line 126 def append_to_main_array(i) # This will append to @array_all_css_classes. i.delete!(',') if i.include? ',' # Kill all ','. i = i.strip if i.is_a? String if i.include? '.' # Get rid of all '.' n = i.count '.' # But we must count it too and act on all those input that have more than one . if n > 1 i = i.split('.').reject {|x| x.empty?} else i.gsub!(/\./,'') end end unless ARRAY_IGNORE_THESE.include?(i) if i.is_a? Array i.each { |entry| append_to_main_array(entry) } else @array_all_css_classes << i unless i.include? ':' # we assume that : is never valid here. end end end |
#dataset? ⇒ Boolean Also known as: dataset
#
dataset?
#
213 214 215 |
# File 'lib/cyberweb/standalone_classes/all_css_classes.rb', line 213 def dataset? @dataset end |
#fetch_data(from = @this_css_file) ⇒ Object
#
fetch_data
This is the actual powerhorse of this method.
#
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/cyberweb/standalone_classes/all_css_classes.rb', line 105 def fetch_data( from = @this_css_file ) if from.is_a? Array _ = [] from.each { |x| _ << readlines(x); _.flatten! } else _ = readlines(from) end # From this point, _ is an Array. _.each { |line| if line.include? '{' content = line[0..(line.index('{') - 1)].strip append_to_main_array(content) end } @dataset = _ end |
#found? ⇒ Boolean
#
found?
This will return those css classes we found.
#
170 171 172 |
# File 'lib/cyberweb/standalone_classes/all_css_classes.rb', line 170 def found? @array_found_these_css_classes end |
#include?(*array) ⇒ Boolean
#
include?
This is the most important method of this class. Use it to find out whether we include the given CSS classes or not.
#
180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/cyberweb/standalone_classes/all_css_classes.rb', line 180 def include?(*array) array.flatten.each { |a| a = a.strip if @array_all_css_classes.include?(a) @array_found_these_css_classes << a else @array_not_registered_css_classes << a end } # Now, do cleanup. Get rid of empty classes. @array_not_registered_css_classes.reject! {|x| x.empty?} end |
#output_result ⇒ Object Also known as: report
#
output_result
#
195 196 197 198 199 200 201 |
# File 'lib/cyberweb/standalone_classes/all_css_classes.rb', line 195 def output_result unless @array_not_registered_css_classes.empty? @array_not_registered_css_classes.each { |line| e 'This class was not found: `'+line+'`.' } end end |
#readlines(from, use_this_encoding = ::Cyberweb::Encoding::ENCODING_TO_USE) ⇒ Object
#
readlines
#
76 77 78 79 80 81 |
# File 'lib/cyberweb/standalone_classes/all_css_classes.rb', line 76 def readlines( from, use_this_encoding = ::Cyberweb::Encoding::ENCODING_TO_USE ) File.readlines(from, encoding: use_this_encoding) end |
#reset ⇒ Object
#
reset
#
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cyberweb/standalone_classes/all_css_classes.rb', line 56 def reset # ======================================================================= # # === @this_css_file # ======================================================================= # @this_css_file = nil # ======================================================================= # # === @dataset # ======================================================================= # @dataset = nil # ======================================================================= # # === @array_all_css_classes # ======================================================================= # @array_all_css_classes = [] @array_not_registered_css_classes = [] @array_found_these_css_classes = [] end |
#result ⇒ Object
#
result
#
161 162 163 |
# File 'lib/cyberweb/standalone_classes/all_css_classes.rb', line 161 def result @array_not_registered_css_classes end |
#run ⇒ Object
#
run
#
220 221 222 223 |
# File 'lib/cyberweb/standalone_classes/all_css_classes.rb', line 220 def run fetch_data output_result end |
#set_this_css_file(i) ⇒ Object
#
set_this_css_file
#
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/cyberweb/standalone_classes/all_css_classes.rb', line 86 def set_this_css_file(i) i = CSS_DIR if i == :default if File.exist? i if File.directory?(i) i = Dir[CSS_DIR+'*'] else i = CSS_DIR+i unless i.include? '/' end @this_css_file = i else raise 'But the file `'+i+'` does not exist!' end end |