Class: Ordinary::Normalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/ordinary/normalizer.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &process) ⇒ Normalizer

Returns a new instance of Normalizer.



4
5
6
7
8
# File 'lib/ordinary/normalizer.rb', line 4

def initialize(options = {}, &process)
  @determine = extract_determiner(options)
  @context   = options[:on]
  @process   = process
end

Instance Method Details

#coming_under?(model) ⇒ Boolean

Determine if a model coming under a target of the normalizer.

Parameters:

  • model (ActiveModel::Model)

    a model to determine if be a target of the normalizer

Returns:

  • (Boolean)

    whether the model is a target of the normalizer



23
24
25
# File 'lib/ordinary/normalizer.rb', line 23

def coming_under?(model)
  @determine.nil? or !!@determine.call(model)
end

#normalize(value) ⇒ Object

Normalize a value by the normalizer.

Parameters:

  • value (Object)

    a value to normalize

Returns:

  • (Object)

    a normalized value



14
15
16
# File 'lib/ordinary/normalizer.rb', line 14

def normalize(value)
  @process.call(value)
end

#run_at?(context) ⇒ Boolean

Determine if

Parameters:

  • context (Symbol)

    a context to determine

Returns:

  • (Boolean)

    whether



31
32
33
# File 'lib/ordinary/normalizer.rb', line 31

def run_at?(context)
  @context.nil? or (@context == context)
end