Class: INatGet::Data::DSL::Dataset
#check_shutdown!, check_shutdown!, #shutdown?, shutdown?
#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
20
21
22
|
# File 'lib/inat-get/data/dsl/dataset.rb', line 20
def condition
@condition
end
|
#key ⇒ Object?
17
18
19
|
# File 'lib/inat-get/data/dsl/dataset.rb', line 17
def key
@key
end
|
Instance Method Details
#%(field) ⇒ List
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
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
|
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
|
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
|
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
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
46
47
48
|
# File 'lib/inat-get/data/dsl/dataset.rb', line 46
def connected?
!!@dataset
end
|
#count ⇒ 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.
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
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
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
33
34
35
|
# File 'lib/inat-get/data/dsl/dataset.rb', line 33
def updated?
@updated
end
|
#where(condition = nil, **query) ⇒ Dataset
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
|