Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/broadway/ext.rb
Instance Method Summary collapse
- #/(len) ⇒ Object
- #chunk(pieces) ⇒ Object
- #recursively_symbolize_keys! ⇒ Object
-
#taggify(space = " ", separator = ", ", max = 10_000) ⇒ Object
separator = “, ”, max = 10_000 quote = true|false.
Instance Method Details
#/(len) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/broadway/ext.rb', line 50 def / len a = [] each_with_index do |x,i| a << [] if i % len == 0 a.last << x end a end |
#chunk(pieces) ⇒ Object
45 46 47 48 |
# File 'lib/broadway/ext.rb', line 45 def chunk(pieces) q, r = length.divmod(pieces) (0..pieces).map { |i| i * q + [r, i].min }.enum_cons(2).map { |a, b| slice(a...b) } end |
#recursively_symbolize_keys! ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/broadway/ext.rb', line 24 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
37 38 39 40 41 42 |
# File 'lib/broadway/ext.rb', line 37 def taggify(space = " ", separator = ", ", max = 10_000) quoted = !(separator =~ /\s+/).nil? chop(separator, max) do |word| word.taggify(space, quoted) end.join(separator) end |