Class: Cyberweb::AllCssClasses

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_fileObject (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

.[](i) ⇒ Object

#

AllCssClasses[]

#


206
207
208
# File 'lib/cyberweb/standalone_classes/all_css_classes.rb', line 206

def self.[](i)
  self.new(i)
end

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?

#

Returns:

  • (Boolean)


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.

#

Returns:

  • (Boolean)


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.

#

Returns:

  • (Boolean)


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_resultObject 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

#resetObject

#

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

#resultObject

#

result

#


161
162
163
# File 'lib/cyberweb/standalone_classes/all_css_classes.rb', line 161

def result
  @array_not_registered_css_classes
end

#runObject

#

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

#test(i) ⇒ Object

#

test

#


149
150
151
152
153
154
155
156
# File 'lib/cyberweb/standalone_classes/all_css_classes.rb', line 149

def test(i) # We test input here simply.
  if i.is_a? String
    i = i.split(N)
    include?(i)
  end
  fetch_data
  report
end