Class: Cyberweb::ObtainCssRules

Inherits:
Base
  • Object
show all
Defined in:
lib/cyberweb/utility_scripts/obtain_css_rules/obtain_css_rules.rb

Overview

Cyberweb::ObtainCssRules

Constant Summary

Constants inherited from Base

Base::HOME_DIRECTORY_OF_THE_USER_X, Base::NAMESPACE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#be_verbose, #be_verbose?, #cascading_style_sheets_directory?, #cd, #commandline_mode?, #copyright?, #css_comment, #delete_directory, #do_toggle, #e, #echo_raw, #filename?, #full_path_to_image_directory?, #html_colours?, #html_image, #htmlentities, #img_dir?, #infer_the_namespace, #initialize_the_configuration, #is_a_file?, #is_a_video_file?, #is_an_image_file?, #is_on_roebe?, #last_tag_used?, #last_tag_used_first_element?, #last_tag_used_id?, #mkdir, #mode?, #namespace?, #open_in_browser, #opne, #opnn, #remove_comments_from_this_string_but_preserve_CSS_rules, #remove_html, #return_all_directories, #return_date, #return_program_name, #return_pwd, #ruby_header?, #server_base_directory?, #set_commandline_mode, #set_last_tag_used, #update_the_image_directory, #use_this_relative_directory_for_custom_images?, #www_mode?

Methods included from BaseModule::FileRelatedFunctionality

#copy_this_file, #cpr, #delete_file, #filename_without_extension?, #read_file_via_utf8_encoding

Methods included from BaseModule

#attach_these_constants, #base_dir?, #beautiful_url, #cd, #create_the_internal_hash, #doctype?, #ee, #ensure_main_encoding, #esystem, #html_templates, #initialize_the_config_if_the_config_hash_is_empty, #internal_hash?, #log_dir?, #no_http, #random_alphabet_characters, #rarrow?, #rds, #remove_comments_from_this_string, #remove_numbers, #require_the_html_templates, #require_these, #return_file_size_in_kb_of, #return_html_comment, #ruby_sitelib_dir?, #sanitize_this_id, #server_base_directory?, #string_remote_image, #today?, #try_to_require_rack, #try_to_require_the_open_gem, #write_what_into

Methods included from BaseModule::ContentType

#content_type_is_html, #content_type_is_jpeg, #content_type_is_json, #content_type_is_plain_text

Methods included from BaseModule::CommandlineArguments

#append_to_the_commandline_arguments, #commandline_arguments?, #first_argument?, #parse_these_commandline_arguments, #second_argument?, #set_commandline_arguments

Methods included from BaseModule::Colours

#all_html_colours, #lightgreen, #rev, #sdir, #sfancy, #sfile, #simp, #steelblue, #tomato

Constructor Details

#initialize(i = ARGV, run_already = true) ⇒ ObtainCssRules

#

initialize

#


27
28
29
30
31
32
33
34
# File 'lib/cyberweb/utility_scripts/obtain_css_rules/obtain_css_rules.rb', line 27

def initialize(
    i           = ARGV,
    run_already = true
  )
  reset
  set_commandline_arguments(i)
  run if run_already
end

Class Method Details

.[](i = ARG) ⇒ Object

#

Cyberweb::ObtainCssRules[]

#


159
160
161
# File 'lib/cyberweb/utility_scripts/obtain_css_rules/obtain_css_rules.rb', line 159

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

Instance Method Details

#parse(dataset) ⇒ Object

#

parse

Here we assume that the dataset is an Array.

#


123
124
125
126
127
128
129
130
131
# File 'lib/cyberweb/utility_scripts/obtain_css_rules/obtain_css_rules.rb', line 123

def parse(dataset)
  if dataset.any? {|line| line.start_with?(@seek_this_CSS_class) }
    # Ok, here we found a match, so output the rule.
    selection = dataset.select {|line| line.start_with?(@seek_this_CSS_class) }
    set_result(selection)
  # else # in this case we found no match. 
  # 
  end
end

#parse_string(i) ⇒ Object

#

parse_string

#


136
137
138
139
140
# File 'lib/cyberweb/utility_scripts/obtain_css_rules/obtain_css_rules.rb', line 136

def parse_string(i)
  if i.start_with?(@seek_this_CSS_class)
    set_result(i)
  end
end

#raw_contentObject Also known as: raw_body?, raw_content?, body?

#

raw_content

This method will return the raw body of the CSS rule at hand. So if the content is ‘{ margin-left: 1em; margin-right: 1em; }’ then only the part between the two ” will returned via this method here.

Otherwise the original @result is returned.

Currently this method will remove excessive ‘ ’ too, and .strip() on the resulting String.

#


108
109
110
111
112
113
114
# File 'lib/cyberweb/utility_scripts/obtain_css_rules/obtain_css_rules.rb', line 108

def raw_content
  if @result.include?('{')
    return @result.scan(/{(.+)}/).flatten.first.to_s.squeeze(' ').strip
  else
    return @result
  end
end

#resetObject

#

reset (reset tag)

#


39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cyberweb/utility_scripts/obtain_css_rules/obtain_css_rules.rb', line 39

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @seek_this_CSS_class
  # ======================================================================= #
  @seek_this_CSS_class = '.mars1em'
  # ======================================================================= #
  # === @result
  # ======================================================================= #
  @result = nil 
end

#result?Boolean

#

result?

#

Returns:

  • (Boolean)


55
56
57
# File 'lib/cyberweb/utility_scripts/obtain_css_rules/obtain_css_rules.rb', line 55

def result?
  @result
end

#runObject

#

run (run tag)

#


145
146
147
148
149
150
151
152
153
154
# File 'lib/cyberweb/utility_scripts/obtain_css_rules/obtain_css_rules.rb', line 145

def run
  _ = cascading_style_sheets_directory?
  all_local_css_files = Dir[_+'*.css']
  all_local_css_files.each {|this_CSS_file|
    if File.exist?(this_CSS_file)
      dataset = File.readlines(this_CSS_file)
      parse(dataset)
    end
  }
end

#sanitize_the_resultObject

#

sanitize_the_result

Currently this method will only get rid of excess ‘ ’ characters.

#


74
75
76
# File 'lib/cyberweb/utility_scripts/obtain_css_rules/obtain_css_rules.rb', line 74

def sanitize_the_result
  @result.squeeze!(' ')
end

#seek_this_CSS_class?Boolean Also known as: seek?

#

seek_this_CSS_class?

#

Returns:

  • (Boolean)


92
93
94
# File 'lib/cyberweb/utility_scripts/obtain_css_rules/obtain_css_rules.rb', line 92

def seek_this_CSS_class?
  @seek_this_CSS_class
end

#set_result(i) ⇒ Object

#

set_result

#


62
63
64
65
66
67
# File 'lib/cyberweb/utility_scripts/obtain_css_rules/obtain_css_rules.rb', line 62

def set_result(i)
  if i.is_a? Array
    i = i.first
  end
  @result = i
end

#set_seek_this_CSS_class(i) ⇒ Object Also known as: set_seek_this

#

set_seek_this_CSS_class

#


81
82
83
84
85
86
87
# File 'lib/cyberweb/utility_scripts/obtain_css_rules/obtain_css_rules.rb', line 81

def set_seek_this_CSS_class(i)
  i = i.dup
  unless i.start_with?('.')
    i.prepend('.')
  end
  @seek_this_CSS_class = i
end