Class: Eco::API::Common::People::PersonAttributeParser

Inherits:
Language::Models::ParserSerializer show all
Defined in:
lib/eco/api/common/people/person_attribute_parser.rb

Overview

Class to define a parser/serializer.

Instance Attribute Summary

Attributes inherited from Language::Models::ParserSerializer

#attr

Instance Method Summary collapse

Methods inherited from Language::Models::ParserSerializer

#initialize, #parse, #parser_category?, #serialize, #serializer_category?

Constructor Details

This class inherits a constructor from Eco::Language::Models::ParserSerializer

Instance Method Details

#active_when_all?(*attrs) ⇒ Boolean

Helper to build the active_when condition.

Returns:

  • (Boolean)


64
65
66
67
68
69
# File 'lib/eco/api/common/people/person_attribute_parser.rb', line 64

def active_when_all?(*attrs)
  Proc.new do |source_data|
    keys = data_keys(source_data)
    attrs.all? {|key| keys.include?(key)}
  end
end

#active_when_any?(*attrs) ⇒ Boolean

Helper to build the active_when condition.

Returns:

  • (Boolean)


56
57
58
59
60
61
# File 'lib/eco/api/common/people/person_attribute_parser.rb', line 56

def active_when_any?(*attrs)
  Proc.new do |source_data|
    keys = data_keys(source_data)
    attrs.any? {|key| keys.include?(key)}
  end
end

#def_parser(phase = :internal, active_when: nil, &block) ⇒ Object

Note:
  • additionally, you can declare a callback active: to determine if when the

parser will be active/used.

  • this is important to help avoiding to set values that are not present in the input entry.
  • if you have doubts about using it or not, do not use it. By default, an attribute paraser is active if in the entry to parse the internal attribute is present.

Parameters:

  • phase (Symbol) (defaults to: :internal)

    the phase when this parser should be active. Must be one of [:internal, :final]

  • active_when (Proc) (defaults to: nil)

    that expects a list of internal attributes or the internal entry itself.

See Also:



27
28
29
30
# File 'lib/eco/api/common/people/person_attribute_parser.rb', line 27

def def_parser(phase = :internal, active_when: nil, &block)
  @active_when = attribute_present(active_when)
  super(phase, &block)
end

#def_serializer(phase = :person, &block) ⇒ Object

Parameters:

  • phase (Symbol) (defaults to: :person)

    the phase when this serializer should be active. Must be one of [:person, :final, :internal]



34
35
36
# File 'lib/eco/api/common/people/person_attribute_parser.rb', line 34

def def_serializer(phase = :person, &block)
  super(phase, &block)
end

#parser_active?(source_data, phase = :any) ⇒ Boolean

Determines if for a given source data to parse, this parser should be active or not.

Parameters:

  • phase (Symbol) (defaults to: :any)

    the phase when this parser should be active. Must be one of [:internal, :final]

Returns:

  • (Boolean)

    true if there's parser defined and source_data activates it.



42
43
44
# File 'lib/eco/api/common/people/person_attribute_parser.rb', line 42

def parser_active?(source_data, phase = :any)
  (phase == :any || parser_category?(phase)) && @active_when.call(source_data)
end

#required_attrsRequiredAttrs

Note:
  • This was introduced at a later stage and might not be available for certain org-parsers configs

Returns:

  • (RequiredAttrs)


12
13
14
15
# File 'lib/eco/api/common/people/person_attribute_parser.rb', line 12

def required_attrs
  @required_attrs ||= @dependencies[:required_attrs]
  #@required_attrs ||= RequiredAttrs.new(attr, :unkown, [attr])
end

#serializer_active?(phase = :any) ⇒ Boolean

Determines a serializer should be active or not.

Parameters:

  • phase (Symbol) (defaults to: :any)

    the phase when this serializer should be active. Must be one of [:person, :final, :internal]

Returns:

  • (Boolean)

    true if there's serializer defined.



50
51
52
# File 'lib/eco/api/common/people/person_attribute_parser.rb', line 50

def serializer_active?(phase = :any)
  (phase == :any) || serializer_category?(phase)
end