Sha256: d3f4f7011bea326b648d7e25fa7134c1601e1ff1bac7e249b519fe2d0b99e6b6

Contents?: true

Size: 893 Bytes

Versions: 7

Compression:

Stored size: 893 Bytes

Contents

module Soroban

  # Define a new function.
  def self.define(function_hash)
    @@functions ||= {}
    function_hash.each { |name, callback| @@functions[name] = callback }
  end 

  # Return an array of all defined functions.
  def self.functions
    @@functions.keys.map { |f| f.to_s }
  end

  # Call the named function within the context of the specified sheet.
  def self.call(sheet, name, *args)
    function = name.upcase.to_sym
    raise Soroban::UndefinedError, "No such function '#{function}'" unless @@functions[function]
    sheet.instance_exec(*args, &@@functions[function])
  end

end

require 'soroban/functions/average'
require 'soroban/functions/sum'
require 'soroban/functions/vlookup'
require 'soroban/functions/if'
require 'soroban/functions/and'
require 'soroban/functions/or'
require 'soroban/functions/not'
require 'soroban/functions/max'
require 'soroban/functions/min'

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
soroban-0.4.0 lib/soroban/functions.rb
soroban-0.3.1 lib/soroban/functions.rb
soroban-0.3.0 lib/soroban/functions.rb
soroban-0.2.0 lib/soroban/functions.rb
soroban-0.1.1 lib/soroban/functions.rb
soroban-0.1.0 lib/soroban/functions.rb
Soroban-0.1.0 lib/soroban/functions.rb