Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/curly/string.rb,
lib/curly/curl/html.rb
Overview
String helpers
Instance Method Summary collapse
-
#clean ⇒ String
Remove extra spaces and newlines, compress space between tags.
-
#clean! ⇒ Object
Destructive version of #clean.
-
#clean_output ⇒ Array
Clean up output and return a single-item array.
-
#ensure_array ⇒ Array
Ensure that an object is an array.
-
#normalize_browser_type(default = :none) ⇒ Symbol
Convert a browser type string to a symbol.
-
#normalize_image_type(default = :all) ⇒ Symbol
Convert an image type string to a symbol.
-
#normalize_screenshot_type(default = :none) ⇒ Symbol
Convert a screenshot type string to a symbol.
- #remove_entities ⇒ Object
-
#strip_tags ⇒ String
Remove HTML tags from a string.
-
#strip_tags! ⇒ Object
Destructive version of #strip_tags.
Instance Method Details
#clean ⇒ String
Remove extra spaces and newlines, compress space between tags
14 15 16 |
# File 'lib/curly/string.rb', line 14 def clean gsub(/[\t\n ]+/m, ' ').gsub(/> +</, '><') end |
#clean! ⇒ Object
Destructive version of #clean
32 33 34 |
# File 'lib/curly/string.rb', line 32 def clean! replace clean end |
#clean_output ⇒ Array
Clean up output and return a single-item array
102 103 104 105 |
# File 'lib/curly/string.rb', line 102 def clean_output output = ensure_array output.clean_output end |
#ensure_array ⇒ Array
Ensure that an object is an array
112 113 114 |
# File 'lib/curly/string.rb', line 112 def ensure_array return [self] end |
#normalize_browser_type(default = :none) ⇒ Symbol
Convert a browser type string to a symbol
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/curly/string.rb', line 68 def normalize_browser_type(default = :none) case self.to_s when /^c/i :chrome when /^f/i :firefox else default.is_a?(Symbol) ? default.to_sym : default.normalize_browser_type end end |
#normalize_image_type(default = :all) ⇒ Symbol
Convert an image type string to a symbol
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/curly/string.rb', line 50 def normalize_image_type(default = :all) case self.to_s when /^[sp]/i :srcset when /^i/i :img when /^o/i :opengraph else default.is_a?(Symbol) ? default.to_sym : default.normalize_image_type end end |
#normalize_screenshot_type(default = :none) ⇒ Symbol
Convert a screenshot type string to a symbol
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/curly/string.rb', line 84 def normalize_screenshot_type(default = :none) case self.to_s when /^f/i :full_page when /^p/i :print_page when /^v/i :visible else default.is_a?(Symbol) ? default.to_sym : default.normalize_browser_type end end |
#remove_entities ⇒ Object
6 7 8 |
# File 'lib/curly/curl/html.rb', line 6 def remove_entities gsub(/ /, ' ') end |
#strip_tags ⇒ String
Remove HTML tags from a string
23 24 25 |
# File 'lib/curly/string.rb', line 23 def gsub(%r{</?.*?>}, '') end |
#strip_tags! ⇒ Object
Destructive version of #strip_tags
41 42 43 |
# File 'lib/curly/string.rb', line 41 def replace end |