Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/curly/string.rb,
lib/curly/curl/html.rb

Overview

String helpers

Instance Method Summary collapse

Instance Method Details

#cleanString

Remove extra spaces and newlines, compress space between tags

Returns:



14
15
16
# File 'lib/curly/string.rb', line 14

def clean
  gsub(/[\t\n ]+/m, ' ').gsub(/> +</, '><')
end

#clean!Object

Destructive version of #clean

See Also:



32
33
34
# File 'lib/curly/string.rb', line 32

def clean!
  replace clean
end

#clean_outputArray

Clean up output and return a single-item array

Returns:

  • (Array)

    output array



102
103
104
105
# File 'lib/curly/string.rb', line 102

def clean_output
  output = ensure_array
  output.clean_output
end

#ensure_arrayArray

Ensure that an object is an array

Returns:

  • (Array)

    object as 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

Returns:

  • (Symbol)

    :chrome, :firefox



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

Returns:

  • (Symbol)

    :srcset, :img, :opengraph, :all



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

Returns:

  • (Symbol)

    :full_page, :print_page, :visible



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_entitiesObject



6
7
8
# File 'lib/curly/curl/html.rb', line 6

def remove_entities
  gsub(/&nbsp;/, ' ')
end

#strip_tagsString

Remove HTML tags from a string

Returns:

  • (String)

    stripped string



23
24
25
# File 'lib/curly/string.rb', line 23

def strip_tags
  gsub(%r{</?.*?>}, '')
end

#strip_tags!Object

Destructive version of #strip_tags

See Also:



41
42
43
# File 'lib/curly/string.rb', line 41

def strip_tags!
  replace strip_tags
end