Class: INatGet::Data::DSL::Dataset
#check_shutdown!, check_shutdown!, #shutdown?, shutdown?
#AND, #ANYTHING, #NOT, #NOTHING, #OR, #Q, #console, #erb_report, #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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/inat-get/data/dsl/dataset.rb', line 85
def % field
values = get_field_values field
current = 0
total = if values.respond_to?(:count)
values.count
else
values.size
end
Thread::current[:total] ||= 0
Thread::current[:total] += total
console.update status: "grouping by #{ field }...", total: Thread::current[:total]
Thread::current[:current] ||= 0
dss = values.map do |value|
current += 1
Thread::current[:current] += 1
console.update status: "grouping by #{ field }...", current: Thread::current[:current]
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)
ensure
if current < total
Thread::current[:total] -= total - current
console.update total: Thread::current[:total]
end
console.update status: 'grouped'
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
160
161
162
163
|
# File 'lib/inat-get/data/dsl/dataset.rb', line 160
def count
connect!
@dataset.count
end
|
#each {|obj| ... } ⇒ void
This method returns an undefined value.
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/inat-get/data/dsl/dataset.rb', line 134
def each
return to_enum(__method__) unless block_given?
connect!
total = @dataset.count
Thread::current[:total] ||= 0
Thread::current[:total] += total
console.update status: 'processing...', total: Thread::current[:total]
current = 0
Thread::current[:current] ||= 0
@dataset.each do |item|
check_shutdown!
current += 1
Thread::current[:current] += 1
console.update status: 'processing...', current: Thread::current[:current]
yield item
end
ensure
if current < total
Thread::current[:total] -= total - current
console.update total: Thread::current[:total]
end
console.update status: 'processed'
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
119
120
121
122
123
|
# File 'lib/inat-get/data/dsl/dataset.rb', line 119
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
|