Class: INatGet::Data::Parser::Part::PK Private

Inherits:
INatGet::Data::Parser::Part show all
Defined in:
lib/inat-get/data/parsers/defs/pk.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

Constructor Details

#initialize(parser, **aliases) ⇒ PK

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 PK.



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

def initialize parser, **aliases
  super parser
  @aliases = aliases
  @registered = Set::new
end

Instance Method Details

#parse(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.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/inat-get/data/parsers/defs/pk.rb', line 15

def parse source
  @pk_cols ||= Array(parser.model.primary_key)
  result = {}
  @pk_cols.each do |col|
    src_col = @aliases[col] || col
    result[col] = source[src_col]
  end
  key = result.values_at(*@pk_cols)
  if @registered.include?(key)
    result[:_registered] = key
  end
  @registered << key
  result
end