Class: INatGet::Data::DSL::Condition::AND

Inherits:
INatGet::Data::DSL::Condition show all
Defined in:
lib/inat-get/data/dsl/conditions/and.rb

Metadata collapse

Attributes inherited from INatGet::Data::DSL::Condition

#manager

Operators collapse

Constructor collapse

Methods inherited from INatGet::Data::DSL::Condition

#!, #api_query, #sequel_query, #|

Methods included from INatGet::Data::DSL

#AND, #ANYTHING, #NOT, #NOTHING, #OR, #Q, #finish_time, #get_identification, #get_observation, #get_place, #get_project, #get_taxon, #get_user, #now, #select_identifications, #select_observations, #select_places, #select_projects, #select_taxa, #select_users, #start_time, #time_range, #today, #version, #version!, #version?, #version_alias

Instance Attribute Details

#modelclass of Sequel::Model (readonly)

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:

  • (class of Sequel::Model)


21
22
23
# File 'lib/inat-get/data/dsl/conditions/and.rb', line 21

def model
  @operands.map(&:model).find { |h| !h.nil? }
end

#operandsArray<Condition> (readonly)

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:



11
12
13
# File 'lib/inat-get/data/dsl/conditions/and.rb', line 11

def operands
  @operands
end

Class Method Details

.[](*operands) ⇒ Condition

Returns:



52
53
54
55
56
57
58
59
# File 'lib/inat-get/data/dsl/conditions/and.rb', line 52

def [] *operands
  return INatGet::Data::DSL::ANYTHING if operands.empty?
  return INatGet::Data::DSL::NOTHING if operands.include?(INatGet::Data::DSL::NOTHING)
  operands.delete INatGet::Data::DSL::ANYTHING
  operands.uniq!
  return operands.first if operands.size == 1
  new(*operands).freeze
end

Instance Method Details

#&(other) ⇒ Condition

Returns:



30
31
32
33
34
35
36
# File 'lib/inat-get/data/dsl/conditions/and.rb', line 30

def & other
  if other.is_a?(AND)
    AND[ *self.operands, *other.operands ]
  else
    AND[ *self.operands, other ]
  end
end

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/inat-get/data/dsl/conditions/and.rb', line 39

def == other
  return true if self.equal?(other)
  return false unless other.is_a?(AND)
  self.operands.all? { |o| other.operands.include?(o) } && other.operands.all? { |o| self.operands.include?(o) }
end

#and_merge_sets(left, right) ⇒ Object (private)



162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/inat-get/data/dsl/conditions/and.rb', line 162

def and_merge_sets left, right
  sample = left.first
  return ::Set[] if sample.nil?
  return left & right unless sample.is_a?(INatGet::Data::Model::Taxon)
  # Мержим с учетом таксономии
  result = ::Set[]
  left.each do |value|
    result << value if right.any? { |v| v === value }
  end
  right.each do |value|
    result << value if left.any? { |v| v === value }
  end
  INatGet::Data::Model::Taxon::compact_set(*result)
end