Class: Parxer::Callbacks

Inherits:
Array
  • Object
show all
Defined in:
lib/parxer/collections/callbacks.rb

Constant Summary collapse

CALLBACK_TYPES =
i{after_parse_row}

Instance Method Summary collapse

Instance Method Details

#add_callback(type, action, config = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/parxer/collections/callbacks.rb', line 5

def add_callback(type, action, config = {})
  if !CALLBACK_TYPES.include?(type.to_sym)
    raise Parxer::CallbacksError.new("invalid '#{type}' callback type")
  end

  if !action.is_a?(Proc) && !action.is_a?(Symbol)
    raise Parxer::CallbacksError.new("action param must by a Proc or symbol method name")
  end

  self << Parxer::Callback.new(type: type, action: action, config: config || {})
  last
end

#by_type(type) ⇒ Object



18
19
20
# File 'lib/parxer/collections/callbacks.rb', line 18

def by_type(type)
  select { |callback| callback.type == type.to_sym }
end