Module: Hatemile::Util::CommonFunctions
- Defined in:
- lib/hatemile/util/common_functions.rb
Overview
The CommonFunctions module contains the used methods by HaTeMiLe classes.
Constant Summary collapse
- DATA_IGNORE =
The name of attribute for not modify the elements.
'data-ignoreaccessibilityfix'.freeze
Class Method Summary collapse
-
.in_list?(list, string_to_search) ⇒ Boolean
Verify if the list contains the item.
-
.increase_in_list(list, string_to_increase) ⇒ String
Increase a item in a HTML list.
-
.is_valid_element?(element) ⇒ Boolean
Check that the element can be manipulated by HaTeMiLe.
-
.set_list_attributes(element1, element2, attributes) ⇒ void
Copy a list of attributes of a element for other element.
Class Method Details
.in_list?(list, string_to_search) ⇒ Boolean
Verify if the list contains the item.
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/hatemile/util/common_functions.rb', line 71 def self.in_list?(list, string_to_search) if !list.nil? && !list.empty? && !string_to_search.nil? && !string_to_search.empty? elements = list.split(/[ \n\t\r]+/) elements.each do |element| return true if element == string_to_search end end false end |
.increase_in_list(list, string_to_increase) ⇒ String
Increase a item in a HTML list.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/hatemile/util/common_functions.rb', line 51 def self.increase_in_list(list, string_to_increase) if !list.nil? && !list.empty? && !string_to_increase.nil? && !string_to_increase.empty? return list if in_list?(list, string_to_increase) return "#{list} #{string_to_increase}" elsif !list.nil? && !list.empty? return list end string_to_increase end |
.is_valid_element?(element) ⇒ Boolean
Check that the element can be manipulated by HaTeMiLe.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/hatemile/util/common_functions.rb', line 90 def self.is_valid_element?(element) return false if element.has_attribute?(DATA_IGNORE) parent_element = element.get_parent_element return true if parent_element.nil? tag_name = parent_element.get_tag_name if (tag_name != 'BODY') && (tag_name != 'HTML') return is_valid_element?(parent_element) end true end |
.set_list_attributes(element1, element2, attributes) ⇒ void
This method returns an undefined value.
Copy a list of attributes of a element for other element.
36 37 38 39 40 41 42 |
# File 'lib/hatemile/util/common_functions.rb', line 36 def self.set_list_attributes(element1, element2, attributes) attributes.each do |attribute| if element1.has_attribute?(attribute) element2.set_attribute(attribute, element1.get_attribute(attribute)) end end end |