Class: Array

Inherits:
Object show all
Defined in:
lib/arachni/ruby/array.rb

Overview

Copyright 2010-2014 Tasos Laskos <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Instance Method Summary collapse

Instance Method Details

#chunk(pieces = 2) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/arachni/ruby/array.rb', line 43

def chunk( pieces = 2 )
    return self if pieces <= 0

    len    = self.length
    mid    = len / pieces
    chunks = []
    start  = 0

    1.upto( pieces ) do |i|
        last = start + mid
        last = last - 1 unless len % pieces >= i
        chunks << self[ start..last ] || []
        start = last + 1
    end

    chunks
end

#includes_tags?(tags) ⇒ Bool

Returns ‘true` if `self` contains any of the `tags` when objects of both `self` and `tags` are converted to `String`.

Parameters:

  • tags (#to_s, Array<#to_s>)

Returns:

  • (Bool)

    ‘true` if `self` contains any of the `tags` when objects of both `self` and `tags` are converted to `String`.



26
27
28
29
30
31
32
33
# File 'lib/arachni/ruby/array.rb', line 26

def includes_tags?( tags )
    return false if !tags

    tags = [tags].flatten.compact.map( &:to_s )
    return false if tags.empty?

    (self.flatten.compact.map( &:to_s ) & tags).any?
end

#recodeArray

Recursively converts the array’s string data to UTF8.

Returns:

  • (Array)

    Copy of ‘self` with all strings recoded to UTF8.



39
40
41
# File 'lib/arachni/ruby/array.rb', line 39

def recode
    map { |v| v.respond_to?( :recode ) ? v.recode : v }
end