Class: INatGet::Data::Parser::Part::Ancestry Private
- Inherits:
-
Links
- Object
- INatGet::Data::Parser::Part
- Assoc
- Links
- INatGet::Data::Parser::Part::Ancestry
- Defined in:
- lib/inat-get/data/parsers/defs/ancestry.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
Instance Method Summary collapse
-
#initialize(parser, name, source: nil, source_ids: nil) ⇒ Ancestry
constructor
private
A new instance of Ancestry.
- #parse(target, source) ⇒ Object private
Constructor Details
#initialize(parser, name, source: nil, source_ids: nil) ⇒ Ancestry
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 a new instance of Ancestry.
7 8 9 |
# File 'lib/inat-get/data/parsers/defs/ancestry.rb', line 7 def initialize parser, name, source: nil, source_ids: nil super parser, name, model: nil, source: source, source_ids: source_ids end |
Instance Method Details
#parse(target, source) ⇒ Object
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.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/inat-get/data/parsers/defs/ancestry.rb', line 11 def parse target, source @model ||= parser.model data = source[@source] values = if data @model.parser.parse! data.reject { |v| v[:id] == target.id } else ids = source[@source_ids] || [] ids.delete target.id @model.manager.get(*ids) end ids = values.map(&:id) ids << target.id unless ids.include?(target.id) field = @parser.model.association_reflection(@name)[:pks_setter_method].to_s.chomp("=").gsub('_setter', '').to_sym { field => ids } end |