Class: Furud::Functions::Entry

Inherits:
Struct
  • Object
show all
Defined in:
lib/furud/functions.rb,
sig/furud.rbs

Constant Summary collapse

ERROR_HANDLERS =
%w[IF IFERROR IFNA FILTER COUNTIF COUNTIFS SUMIF SUMIFS AVERAGEIF AVERAGEIFS].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#arity ⇒ Object

Returns the value of attribute arity

Returns:

  • (Object) —

    the current value of arity



9
10
11
# File 'lib/furud/functions.rb', line 9

def arity
  @arity
end

#implementation ⇒ Object

Returns the value of attribute implementation

Returns:

  • (Object) —

    the current value of implementation



9
10
11
# File 'lib/furud/functions.rb', line 9

def implementation
  @implementation
end

#name ⇒ Object

Returns the value of attribute name

Returns:

  • (Object) —

    the current value of name



9
10
11
# File 'lib/furud/functions.rb', line 9

def name
  @name
end

#volatile ⇒ Object

Returns the value of attribute volatile

Returns:

  • (Object) —

    the current value of volatile



9
10
11
# File 'lib/furud/functions.rb', line 9

def volatile
  @volatile
end

Instance Method Details

#accepts?(count) ⇒ Boolean

Parameters:

  • (Integer)

Returns:

  • (Boolean)


28
# File 'lib/furud/functions.rb', line 28

def accepts?(count) = arity_match?(count)

#call(*args) ⇒ Object

Parameters:

  • (Object)

Returns:

  • (Object)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/furud/functions.rb', line 12

def call(*args)
  return ErrorValue.new(code: :value) unless arity_match?(args.length)
  unless handles_errors?
    error = args.lazy.map { |value| first_error(value) }.find(&:itself)
    return error if error
  end

  implementation.call(*args)
rescue ZeroDivisionError
  ErrorValue.new(code: :div0)
rescue Math::DomainError, RangeError
  ErrorValue.new(code: :num)
rescue ArgumentError, TypeError, FloatDomainError
  ErrorValue.new(code: :value)
end