Class: INatGet::Data::Parser::Part::Model Private

Inherits:
INatGet::Data::Parser::Part show all
Defined in:
lib/inat-get/data/parsers/defs/model.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, name, model:, source: nil, source_id: nil) ⇒ Model

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



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

def initialize parser, name, model:, source: nil, source_id: nil
  super parser
  @name = name
  @model = model
  @source = source || @name
  @source_id = source_id || "#{ @source }_id".to_sym
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
# File 'lib/inat-get/data/parsers/defs/model.rb', line 15

def parse source
  data = source[@source]
  if data
    { @name => @model.parser.entry!(data) }
  else
    id = source[@source_id]
    if id
      { @name => Array(@model.manager.get(id)).first }
    else
      { @name => nil }
    end
  end
end