Class: Bespoke::Export::Filter::FunctionCall
- Inherits:
-
Object
- Object
- Bespoke::Export::Filter::FunctionCall
- Defined in:
- lib/bespoke/export/filter/function_call.rb
Constant Summary collapse
- EXTRACTION_REGEXP =
/\A(?<function>[^\(]+)\((?<args>[^\)]*)\)\z/- DEFAULT_CUSTOM_FUNCTIONS =
{ 'random_str' => ->(args) { "LOWER(HEX(RANDOMBLOB(#{ args[0].to_i })))" }, }.with_indifferent_access
Instance Attribute Summary collapse
-
#custom_functions ⇒ Object
readonly
Returns the value of attribute custom_functions.
Class Method Summary collapse
Instance Method Summary collapse
-
#arguments ⇒ Object
TODO: Make this type cast integers, booleans and possibly identifiers.
- #extract ⇒ Object
- #function ⇒ Object
-
#initialize(string, custom_functions = {}) ⇒ FunctionCall
constructor
A new instance of FunctionCall.
Constructor Details
#initialize(string, custom_functions = {}) ⇒ FunctionCall
Returns a new instance of FunctionCall.
23 24 25 26 |
# File 'lib/bespoke/export/filter/function_call.rb', line 23 def initialize(string, custom_functions={}) @string = string.strip @custom_functions = DEFAULT_CUSTOM_FUNCTIONS.merge(custom_functions) end |
Instance Attribute Details
#custom_functions ⇒ Object (readonly)
Returns the value of attribute custom_functions.
13 14 15 |
# File 'lib/bespoke/export/filter/function_call.rb', line 13 def custom_functions @custom_functions end |
Class Method Details
.extract_from(string, custom_functions = {}) ⇒ Object
19 20 21 |
# File 'lib/bespoke/export/filter/function_call.rb', line 19 def self.extract_from(string, custom_functions={}) new(string, custom_functions).extract end |
.match?(string) ⇒ Boolean
15 16 17 |
# File 'lib/bespoke/export/filter/function_call.rb', line 15 def self.match?(string) !!EXTRACTION_REGEXP.match(string.strip) end |
Instance Method Details
#arguments ⇒ Object
TODO: Make this type cast integers, booleans and possibly identifiers
41 42 43 |
# File 'lib/bespoke/export/filter/function_call.rb', line 41 def arguments @arguments ||= call_parts[:args].split(',').map(&:strip) end |
#extract ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/bespoke/export/filter/function_call.rb', line 28 def extract if custom_function? Sequel.lit(compile_custom_function) else Sequel.function(function.upcase, *arguments) end end |
#function ⇒ Object
36 37 38 |
# File 'lib/bespoke/export/filter/function_call.rb', line 36 def function call_parts[:function] end |