Class: INatGet::Data::DSL::Condition::OR

Inherits:
INatGet::Data::DSL::Condition show all
Defined in:
lib/inat-get/data/dsl/conditions/or.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)


16
17
18
# File 'lib/inat-get/data/dsl/conditions/or.rb', line 16

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/or.rb', line 11

def operands
  @operands
end

Class Method Details

.[](*operands) ⇒ Condition

Returns:



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

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

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#|(other) ⇒ Condition

Returns:



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

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