Class: INatGet::Data::Parser::Part::PrjRules Private
- Inherits:
-
Assoc
- Object
- INatGet::Data::Parser::Part
- Assoc
- INatGet::Data::Parser::Part::PrjRules
- Defined in:
- lib/inat-get/data/parsers/defs/prjrules.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) ⇒ PrjRules
constructor
private
A new instance of PrjRules.
- #parse(target, source) ⇒ nil private
Constructor Details
#initialize(parser) ⇒ PrjRules
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 PrjRules.
10 11 12 |
# File 'lib/inat-get/data/parsers/defs/prjrules.rb', line 10 def initialize parser super parser, nil, model: nil end |
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.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/inat-get/data/parsers/defs/prjrules.rb', line 15 def parse target, source return nil unless target.is_collection included_places = [] excluded_places = [] included_users = [] excluded_users = [] included_taxa = [] excluded_taxa = [] rules = source[:project_observation_rules] || [] rules.each do |rule| id = rule[:operand_id] next unless id case rule[:operator] when 'observed_in_place?' included_places << id when 'not_observed_in_place?' excluded_places << id when 'observed_in_taxon?' included_taxa << id when 'not_observed_in_taxon?' excluded_taxa << id when 'observed_by_user?' included_users << id when 'not_observed_in_user?' excluded_users << id end end # Fetch objects & ignore inaccessible included_places = p_man.get(*included_places).compact.map(&:id) excluded_places = p_man.get(*excluded_places).compact.map(&:id) included_users = u_man.get(*included_users).compact.map(&:id) excluded_users = u_man.get(*excluded_users).compact.map(&:id) included_taxa = t_man.get(*included_taxa).compact.map(&:id) excluded_taxa = t_man.get(*excluded_taxa).compact.map(&:id) update_rules target.id, pp_mod, :place_id, included_places, false update_rules target.id, pp_mod, :place_id, excluded_places, true update_rules target.id, pt_mod, :taxon_id, included_taxa, false update_rules target.id, pt_mod, :taxon_id, excluded_taxa, true update_rules target.id, pu_mod, :user_id, included_users, false update_rules target.id, pu_mod, :user_id, excluded_users, true nil end |