Class: INatGet::Data::Parser::Part::Children Private

Inherits:
Assoc show all
Defined in:
lib/inat-get/data/parsers/defs/children.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary

Attributes inherited from INatGet::Data::Parser::Part

#parser

Instance Method Summary collapse

Methods inherited from Assoc

#initialize

Methods inherited from INatGet::Data::Parser::Part

#initialize

Constructor Details

This class inherits a constructor from INatGet::Data::Parser::Part::Assoc

Instance Method Details

#parse(target, source) ⇒ nil

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (nil)


6
7
8
9
10
11
12
13
# File 'lib/inat-get/data/parsers/defs/children.rb', line 6

def parse target, source
  data = source[@source] || []
  values = @model.parser.parse!(data.map { |r| r.is_a?(Hash) ? r.merge(owner_id: target.id) : { owner_id: target.id, value: r } })
  pks = values.map { |v| v.primary_key }
  existing = target.send(@name)
  existing.reject { |r| pks.include?(r.primary_key) }.each(&:delete) if existing
  nil
end