Module: INatGet::Data::DSL
- Includes:
- Enum
- Defined in:
- lib/inat-get/data/dsl/dsl.rb,
lib/inat-get/data/managers/taxa.rb,
lib/inat-get/data/managers/users.rb,
lib/inat-get/data/managers/places.rb,
lib/inat-get/data/managers/projects.rb,
lib/inat-get/data/dsl/conditions/base.rb,
lib/inat-get/data/dsl/conditions/base.rb,
lib/inat-get/data/dsl/conditions/query.rb,
lib/inat-get/data/managers/observations.rb,
lib/inat-get/data/managers/identifications.rb,
lib/inat-get/data/dsl/conditions/not.rb,
lib/inat-get/data/dsl/conditions/and.rb,
lib/inat-get/data/dsl/conditions/or.rb
Defined Under Namespace
Classes: Condition, Dataset, List
System Info collapse
- #now ⇒ Time
- #today ⇒ Date
- #version ⇒ Gem::Version
-
#version!(*requirements) ⇒ true
Returns
trueor raise exception. - #version?(*requirements) ⇒ Boolean
- #version_alias ⇒ String
Date Utils collapse
- #finish_time(date: nil, century: nil, decade: nil, year: nil, quarter: nil, season: nil, month: nil, day: nil, week: nil) ⇒ Time
- #start_time(date: nil, century: nil, decade: nil, year: nil, quarter: nil, season: nil, month: nil, day: nil, week: nil) ⇒ Time
- #time_range(date: nil, century: nil, decade: nil, year: nil, quarter: nil, season: nil, month: nil, day: nil, week: nil) ⇒ Range<Time>
Data Querying collapse
- #get_identification(id) ⇒ Model::Identification?
- #get_observation(id) ⇒ Model::Observation?
- #get_place(id) ⇒ Model::Place?
- #get_project(id) ⇒ INatGet::Data::Model::Project?
- #get_taxon(id) ⇒ INatGet::Data::Model::Taxon?
- #get_user(id) ⇒ INatGet::Data::Model::User?
- #select_identifications(*args, **query) ⇒ Enumerable<Model::Identification>
- #select_observations(*args, **query) ⇒ Enumerable<Model::Observation>
- #select_places(*ids) ⇒ Array<Model::Place>
- #select_projects(*args, **query) ⇒ Enumerable<INatGet::Data::Model::Project>
- #select_taxa(*args, **query) ⇒ Enumerable<INatGet::Data::Model::Taxon>
- #select_users(*ids) ⇒ Array<INatGet::Data::Model::User>
Conditions collapse
- #AND(*operands) ⇒ Condition::AND
- #ANYTHING ⇒ Condition::Anything
- #NOT(operand) ⇒ Condition::NOT
- #NOTHING ⇒ Condition::Nothing
- #OR(*operands) ⇒ Condition::OR
- #Q(model = INatGet::Data::Model::Observation, **query) ⇒ Condition::Query
Instance Method Details
#AND(*operands) ⇒ Condition::AND
185 |
# File 'lib/inat-get/data/dsl/conditions/and.rb', line 185 def AND(*operands) = Condition::AND[*operands] |
#ANYTHING ⇒ Condition::Anything
197 |
# File 'lib/inat-get/data/dsl/conditions/base.rb', line 197 ANYTHING = Condition::Anything::instance.freeze |
#finish_time(date: nil) ⇒ Time #finish_time(century: nil) ⇒ Time #finish_time(century: nil, decade: nil) ⇒ Time #finish_time(year: nil) ⇒ Time #finish_time(year: nil, quarter: nil) ⇒ Time #finish_time(year: nil, season: nil) ⇒ Time #finish_time(year: nil, month: nil) ⇒ Time #finish_time(year: nil, month: nil, day: nil) ⇒ Time #finish_time(year: nil, week: nil) ⇒ Time #finish_time(year: nil, day: nil) ⇒ Time
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/inat-get/data/dsl/dsl.rb', line 186 def finish_time date: nil, century: nil, decade: nil, year: nil, quarter: nil, season: nil, month: nil, day: nil, week: nil if date raise ArgumentError, "Too many argument", caller_locations if century || decade || year || quarter || season || month || day || week start_time date: (date + 1) elsif century raise ArgumentError, "Too many argument", caller_locations if year || quarter || season || month || day || week if decade start_time century: century, decade: (decade + 1) else start_time century: (century + 1) end elsif year && quarter raise ArgumentError, "Too many argument", caller_locations if season || month || day || week finish_time year: year, month: (quarter * 3) elsif year && season raise ArgumentError, "Too many argument", caller_locations if month || day || week case season when :winter finish_time year: year, month: 2 when :spring finish_time year: year, month: 5 when :summer finish_time year: year, month: 8 when :autumn finish_time year: year, month: 11 else raise ArgumentError, "Invalid season: #{ season.inspect }", caller_locations end elsif year && month raise ArgumentError, "Too many arguments", caller_locations if week date = Date::civil year, month, (day || -1) finish_time date: date elsif year && week date = Date::commercial year, week, (day || -1) finish_time date: date elsif year && day date = Date::ordinal year, day finish_time date: date elsif year finish_time year: year, month: 12, day: 31 else raise ArgumentError, "Incorrect or empty arguments", caller_locations end end |
#get_identification(id) ⇒ Model::Identification? #get_identification(uuid) ⇒ Model::Identification?
56 |
# File 'lib/inat-get/data/managers/identifications.rb', line 56 def get_identification(id) = INatGet::Data::Manager::Identifications::instance[id] |
#get_observation(id) ⇒ Model::Observation? #get_observation(uuid) ⇒ Model::Observation?
94 |
# File 'lib/inat-get/data/managers/observations.rb', line 94 def get_observation(id) = INatGet::Data::Manager::Observations::instance[id] |
#get_place(id) ⇒ Model::Place? #get_place(uuid) ⇒ Model::Place? #get_place(slug) ⇒ Model::Place?
39 |
# File 'lib/inat-get/data/managers/places.rb', line 39 def get_place(id) = INatGet::Data::Manager::Places::instance[id] |
#get_project(id) ⇒ INatGet::Data::Model::Project?
30 |
# File 'lib/inat-get/data/managers/projects.rb', line 30 def get_project(id) = INatGet::Data::Manager::Projects::instance[id] |
#get_taxon(id) ⇒ INatGet::Data::Model::Taxon?
27 |
# File 'lib/inat-get/data/managers/taxa.rb', line 27 def get_taxon(id) = INatGet::Data::Manager::Taxa::instance[id] |
#get_user(id) ⇒ INatGet::Data::Model::User?
30 |
# File 'lib/inat-get/data/managers/users.rb', line 30 def get_user(id) = INatGet::Data::Manager::Users::instance[id] |
#NOT(operand) ⇒ Condition::NOT
138 |
# File 'lib/inat-get/data/dsl/conditions/not.rb', line 138 def NOT(operand) = Condition::NOT[operand] |
#NOTHING ⇒ Condition::Nothing
192 |
# File 'lib/inat-get/data/dsl/conditions/base.rb', line 192 NOTHING = Condition::Nothing::instance.freeze |
#now ⇒ Time
23 |
# File 'lib/inat-get/data/dsl/dsl.rb', line 23 def now = Time.now |
#OR(*operands) ⇒ Condition::OR
256 |
# File 'lib/inat-get/data/dsl/conditions/or.rb', line 256 def OR(*operands) = Condition::OR[ *operands ] |
#Q(model) ⇒ Proc<Hash => Condition::Query> #Q(model, **query) ⇒ Condition::Query #Q(**query) ⇒ Condition::Query
150 |
# File 'lib/inat-get/data/dsl/conditions/query.rb', line 150 def Q(model = INatGet::Data::Model::Observation, **query) = Condition::Query[ model, validate: true, **query ] |
#select_identifications(*ids) ⇒ Array<Model::Identification> #select_identifications(condition) ⇒ Dataset<Model::Identification> #select_identifications(**query) ⇒ Dataset<Model::Identification>
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/inat-get/data/managers/identifications.rb', line 39 def select_identifications(*args, **query) result = INatGet::Data::Manager::Identifications::instance.get(*args, **query) case result when Sequel::Model [ result ] when nil [] else result end end |
#select_observations(*ids) ⇒ Array<Model::Observation> #select_observations(condition) ⇒ Dataset<Model::Observation> #select_observations(**query) ⇒ Dataset<Model::Observation>
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/inat-get/data/managers/observations.rb', line 77 def select_observations *args, **query result = INatGet::Data::Manager::Observations::instance.get(*args, **query) case result when Sequel::Model [ result ] when nil [] else result end end |
#select_places(*ids) ⇒ Array<Model::Place>
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/inat-get/data/managers/places.rb', line 43 def select_places *ids result = INatGet::Data::Manager::Places::instance.get(*ids) case result when Sequel::Model [ result ] when nil [] else result end end |
#select_projects(*args, **query) ⇒ Enumerable<INatGet::Data::Model::Project>
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/inat-get/data/managers/projects.rb', line 33 def select_projects *args, **query result = INatGet::Data::Manager::Projects::instance.get(*args, **query) case result when Sequel::Model [ result ] when nil [] else result end end |
#select_taxa(*args, **query) ⇒ Enumerable<INatGet::Data::Model::Taxon>
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/inat-get/data/managers/taxa.rb', line 30 def select_taxa *args, **query result = INatGet::Data::Manager::Taxa::instance.get(*args, **query) case result when Sequel::Model [ result ] when nil [] else result end end |
#select_users(*ids) ⇒ Array<INatGet::Data::Model::User>
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/inat-get/data/managers/users.rb', line 33 def select_users *ids result = INatGet::Data::Manager::Users::instance.get(*ids) case result when Sequel::Model [ result ] when nil [] else result end end |
#start_time(date: nil) ⇒ Time #start_time(century: nil) ⇒ Time #start_time(century: nil, decade: nil) ⇒ Time #start_time(year: nil) ⇒ Time #start_time(year: nil, quarter: nil) ⇒ Time #start_time(year: nil, season: nil) ⇒ Time #start_time(year: nil, month: nil) ⇒ Time #start_time(year: nil, month: nil, day: nil) ⇒ Time #start_time(year: nil, week: nil) ⇒ Time #start_time(year: nil, day: nil) ⇒ Time
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/inat-get/data/dsl/dsl.rb', line 114 def start_time date: nil, century: nil, decade: nil, year: nil, quarter: nil, season: nil, month: nil, day: nil, week: nil if date raise ArgumentError, "Too many arguments", caller_locations if century || decade || year || quarter || season || month || day || week date.to_time elsif century raise ArgumentError, "Too many arguments", caller_locations if year || quarter || season || month || day || week start_time year: ((century - 1) * 100 + (decade || 0) * 10 + 1) elsif year && quarter raise ArgumentError, "Too many arguments", caller_locations if season || month || day || week start_time year: year, month: ((quarter - 1) * 3 + 1) elsif year && season raise ArgumentError, "Too many arguments", caller_locations if month || day || week case season when :winter start_time year: (year - 1), month: 12 when :spring start_time year: year, month: 3 when :summer start_time year: year, month: 6 when :autumn start_time year: year, month: 9 else raise ArgumentError, "Invalid season: #{ season.inspect }", caller_locations end elsif year && month raise ArgumentError, "Too many arguments", caller_locations if week date = Date::civil year, month, (day || 1) start_time date: date elsif year && week date = Date::commercial year, week, (day || 1) start_time date: date elsif year && day date = Date::ordinal year, day start_time date: date elsif year start_time year: year, month: 1, day: 1 else raise ArgumentError, "Incorrect or empty arguments", caller_locations end end |
#time_range(date: nil) ⇒ Range<Time> #time_range(century: nil) ⇒ Range<Time> #time_range(century: nil, decade: nil) ⇒ Range<Time> #time_range(year: nil) ⇒ Range<Time> #time_range(year: nil, quarter: nil) ⇒ Range<Time> #time_range(year: nil, season: nil) ⇒ Range<Time> #time_range(year: nil, month: nil) ⇒ Range<Time> #time_range(year: nil, month: nil, day: nil) ⇒ Range<Time> #time_range(year: nil, week: nil) ⇒ Range<Time> #time_range(year: nil, day: nil) ⇒ Range<Time>
79 80 81 |
# File 'lib/inat-get/data/dsl/dsl.rb', line 79 def time_range date: nil, century: nil, decade: nil, year: nil, quarter: nil, season: nil, month: nil, day: nil, week: nil (start_time(date: date, century: century, decade: decade, year: year, quarter: quarter, season: season, month: month, day: day, week: week) ... finish_time(date: date, century: century, decade: decade, year: year, quarter: quarter, season: season, month: month, day: day, week: week)) end |
#today ⇒ Date
20 |
# File 'lib/inat-get/data/dsl/dsl.rb', line 20 def today = Date.today |
#version ⇒ Gem::Version
26 |
# File 'lib/inat-get/data/dsl/dsl.rb', line 26 def version = Gem::Version::create INatGet::Info::VERSION |
#version!(*requirements) ⇒ true
Returns true or raise exception
39 40 41 42 |
# File 'lib/inat-get/data/dsl/dsl.rb', line 39 def version! *requirements raise Gem::DependencyError, "Invalid version: #{ INatGet::Info::VERSION }", caller_locations unless version?(*requirements) true end |
#version?(*requirements) ⇒ Boolean
32 33 34 35 |
# File 'lib/inat-get/data/dsl/dsl.rb', line 32 def version? *requirements requirement = Gem::Requirement::new(*requirements) requirement === version end |
#version_alias ⇒ String
29 |
# File 'lib/inat-get/data/dsl/dsl.rb', line 29 def version_alias = INatGet::Info::VERSION_ALIAS |