Module: DaruLite::Vector::Queryable

Included in:
DaruLite::Vector
Defined in:
lib/daru_lite/vector/queryable.rb

Instance Method Summary collapse

Instance Method Details

#all?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/daru_lite/vector/queryable.rb', line 24

def all?(&)
  @data.data.all?(&)
end

#any?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/daru_lite/vector/queryable.rb', line 20

def any?(&)
  @data.data.any?(&)
end

#empty?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/daru_lite/vector/queryable.rb', line 4

def empty?
  @index.empty?
end

#include_values?(*values) ⇒ true, false

Check if any one of mentioned values occur in the vector

Examples:

dv = DaruLite::Vector.new [1, 2, 3, 4, nil]
dv.include_values? nil, Float::NAN
# => true

Parameters:

  • values (Array)

    values to check for

Returns:

  • (true, false)

    returns true if any one of specified values occur in the vector



16
17
18
# File 'lib/daru_lite/vector/queryable.rb', line 16

def include_values?(*values)
  values.any? { |v| include_with_nan? @data, v }
end

#match(regexp) ⇒ Array

Returns an array of either none or integer values, indicating the regexp matching with the given array.

Examples:

dv = DaruLite::Vector.new(['3 days', '5 weeks', '2 weeks'])
dv.match(/weeks/)

# => [false, true, true]

Parameters:

  • regexp (Regexp)

    A regular matching expression. For example, /weeks/.

Returns:

  • (Array)

    Containing either nil or integer values, according to the match with the given regexp



40
41
42
# File 'lib/daru_lite/vector/queryable.rb', line 40

def match(regexp)
  @data.map { |value| !!(value =~ regexp) }
end