lib/curly/string.rb in curlyq-0.0.9 vs lib/curly/string.rb in curlyq-0.0.10
- old
+ new
@@ -4,10 +4,15 @@
## Remove extra spaces and newlines from a string
##
## @return [String] cleaned string
##
class ::String
+ ## Remove extra spaces and newlines, compress space
+ ## between tags
+ ##
+ ## @return [String] cleaned string
+ ##
def clean
gsub(/[\t\n ]+/m, ' ').gsub(/> +</, '><')
end
##
@@ -38,11 +43,11 @@
end
##
## Convert an image type string to a symbol
##
- ## @return Symbol :srcset, :img, :opengraph, :all
+ ## @return [Symbol] :srcset, :img, :opengraph, :all
##
def normalize_image_type(default = :all)
case self.to_s
when /^[sp]/i
:srcset
@@ -56,11 +61,11 @@
end
##
## Convert a browser type string to a symbol
##
- ## @return Symbol :chrome, :firefox
+ ## @return [Symbol] :chrome, :firefox
##
def normalize_browser_type(default = :none)
case self.to_s
when /^c/i
:chrome
@@ -72,11 +77,11 @@
end
##
## Convert a screenshot type string to a symbol
##
- ## @return Symbol :full_page, :print_page, :visible
+ ## @return [Symbol] :full_page, :print_page, :visible
##
def normalize_screenshot_type(default = :none)
case self.to_s
when /^f/i
:full_page
@@ -85,7 +90,26 @@
when /^v/i
:visible
else
default.is_a?(Symbol) ? default.to_sym : default.normalize_browser_type
end
+ end
+
+ ##
+ ## Clean up output and return a single-item array
+ ##
+ ## @return [Array] output array
+ ##
+ def clean_output
+ output = ensure_array
+ output.clean_output
+ end
+
+ ##
+ ## Ensure that an object is an array
+ ##
+ ## @return [Array] object as Array
+ ##
+ def ensure_array
+ return [self]
end
end