Class: INatGet::Data::DSL::Dataset

Inherits:
Object
  • Object
show all
Includes:
Enumerable, INatGet::Data::DSL, System::Context
Defined in:
lib/inat-get/data/dsl/dataset.rb

Attributes collapse

Methods collapse

Operators collapse

Enumerable collapse

Methods included from System::Context

#check_shutdown!, check_shutdown!, #shutdown?, shutdown?

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

#conditionCondition (readonly)

Returns:



20
21
22
# File 'lib/inat-get/data/dsl/dataset.rb', line 20

def condition
  @condition
end

#keyObject? (readonly)

Returns:

  • (Object, nil)


17
18
19
# File 'lib/inat-get/data/dsl/dataset.rb', line 17

def key
  @key
end

Instance Method Details

#%(field) ⇒ List

Returns:



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/inat-get/data/dsl/dataset.rb', line 85

def % field
  # field = field.to_sym
  values = get_field_values field
  dss = values.map do |value|
    if value.is_a?(INatGet::Data::Model::Taxon)
      query = Q(self.condition.model, :taxon => value )
    else
      query = Q(self.condition.model, field.to_s.singular.to_sym => value )
    end
    INatGet::Data::DSL::Dataset::new(value, self.condition & query, self.updated?)
  end
  INatGet::Data::DSL::List::new(*dss)
end

#*(other) ⇒ Dataset

Returns:



75
76
77
# File 'lib/inat-get/data/dsl/dataset.rb', line 75

def * other
  INatGet::Data::DSL::Dataset::new(self.key, self.condition & other.condition, self.updated? || other.updated?)
end

#+(other) ⇒ Dataset

Returns:



70
71
72
# File 'lib/inat-get/data/dsl/dataset.rb', line 70

def + other
  INatGet::Data::DSL::Dataset::new(self.key, self.condition | other.condition, self.updated? && other.updated?)
end

#-(other) ⇒ Dataset

Returns:



80
81
82
# File 'lib/inat-get/data/dsl/dataset.rb', line 80

def - other
  INatGet::Data::DSL::Dataset::new(self.key, self.condition & !other.condition, self.updated?)
end

#connect!self

Returns:

  • (self)


51
52
53
54
55
56
# File 'lib/inat-get/data/dsl/dataset.rb', line 51

def connect!
  return self if connected?
  update!
  @dataset = @condition.model.where @condition.sequel_query
  self
end

#connected?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/inat-get/data/dsl/dataset.rb', line 46

def connected?
  !!@dataset
end

#countInteger

Returns:

  • (Integer)


125
126
127
128
# File 'lib/inat-get/data/dsl/dataset.rb', line 125

def count
  connect!
  @dataset.count
end

#each {|obj| ... } ⇒ void

This method returns an undefined value.

Yields:

  • Block

Yield Parameters:

  • obj (Sequel::Model)


115
116
117
118
119
120
121
122
# File 'lib/inat-get/data/dsl/dataset.rb', line 115

def each &block
  return to_enum(__method__) unless block_given?
  connect!
  @dataset.each do |item|
    check_shutdown!
    block.call item
  end
end

#reset!self

Returns:

  • (self)


59
60
61
62
63
# File 'lib/inat-get/data/dsl/dataset.rb', line 59

def reset!
  @updated = false
  @dataset = nil
  self
end

#update!self

Returns:

  • (self)


38
39
40
41
42
43
44
# File 'lib/inat-get/data/dsl/dataset.rb', line 38

def update!
  return self if @updated
  updater = @condition.manager.updater
  updater.update! @condition
  @updated = true
  self
end

#updated?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/inat-get/data/dsl/dataset.rb', line 33

def updated?
  @updated
end

#where(condition = nil, **query) ⇒ Dataset

Returns:



100
101
102
103
104
# File 'lib/inat-get/data/dsl/dataset.rb', line 100

def where condition = nil, **query
  condition ||= ANYTHING
  condition &= Q(@condition.model, **query)
  INatGet::Data::DSL::Dataset::new(self.key, self.condition & condition, self.updated?)
end