Class: FilterRename::FilterNumber

Inherits:
FilterBase
  • Object
show all
Includes:
IndexedParams
Defined in:
lib/filter_rename/filter_base.rb

Overview

Base class for all the number oriented filters.

Instance Attribute Summary

Attributes included from IndexedParams

#items, #params, #params_expanded

Class Method Summary collapse

Methods included from IndexedParams

#filter, #indexed_params, #indexes, #normalize_index, #self_targeted?, #string_to_loop

Methods inherited from FilterBase

#current_target, #filter, #get_config, #get_string, #get_words, #initialize, #match?, #set_config, #set_string, #wrap_regex

Constructor Details

This class inherits a constructor from FilterRename::FilterBase

Class Method Details

.calculator(num, expr) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/filter_rename/filter_base.rb', line 202

def self.calculator(num, expr)
  @@calc ||= Keisan::Calculator.new
  begin
    @@calc.evaluate("gt()")
  rescue StandardError
    @@calc.define_function!(:gt, ->(x) { num > x })
    @@calc.define_function!(:lt, ->(x) { num < x })
    @@calc.define_function!(:gte, ->(x) { num >= x })
    @@calc.define_function!(:lte, ->(x) { num <= x })
    @@calc.define_function!(:inc, ->(x) { num + x })
    @@calc.define_function!(:mult, ->(x) { num * x })
  end

  @@calc.evaluate(expr)
end