Class: Array

Inherits:
Object show all
Defined in:
lib/ubiquitously/extensions/core.rb

Instance Method Summary collapse

Instance Method Details

#chop(separator = "", max = 40, &block) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ubiquitously/extensions/core.rb', line 55

def chop(separator = "", max = 40, &block)
  return self if self.join(separator).length < max # opt.
  result = []
  self.each do |word|
    break if (result.join(separator).length + word.length > max)
    word = yield word if block_given?
    result << word
    result
  end
  result
end

#recursively_symbolize_keys!Object



79
80
81
82
83
84
85
86
87
# File 'lib/ubiquitously/extensions/core.rb', line 79

def recursively_symbolize_keys!
  self.each do |item|
    if item.is_a? Hash
      item.recursively_symbolize_keys!
    elsif item.is_a? Array
      item.recursively_symbolize_keys!
    end
  end
end

#taggify(space = " ", separator = ", ", max = 10_000) ⇒ Object

separator = “, ”, max = 10_000 quote = true|false



70
71
72
73
74
75
76
77
# File 'lib/ubiquitously/extensions/core.rb', line 70

def taggify(space = " ", separator = ", ", max = 10_000)
  quoted = !(separator =~ /\s+/).nil?
  chop(separator, max) do |word|
    result = word.downcase.strip.gsub(/[^a-z0-9\.]/, space).squeeze(space)
    result = "\"#{result}\"" if quoted && !(result =~ /\s+/).nil?
    result
  end.join(separator)
end