Module: INatGet::Data::DSL

Includes:
Enum
Included in:
App::Task, Condition, Dataset, List
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

Date Utils collapse

Data Querying collapse

Conditions collapse

Instance Method Details

#AND(*operands) ⇒ Condition::AND

Parameters:

Returns:



185
# File 'lib/inat-get/data/dsl/conditions/and.rb', line 185

def AND(*operands) = Condition::AND[*operands]

#ANYTHINGCondition::Anything

Returns:



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

Overloads:

  • #finish_time(date: nil) ⇒ Time

    Parameters:

    • date (Date) (defaults to: nil)
  • #finish_time(century: nil) ⇒ Time

    Parameters:

    • century (Integer) (defaults to: nil)
  • #finish_time(century: nil, decade: nil) ⇒ Time

    Parameters:

    • century (Integer) (defaults to: nil)
    • decade (Integer) (defaults to: nil)
  • #finish_time(year: nil) ⇒ Time

    Parameters:

    • year (Integer) (defaults to: nil)
  • #finish_time(year: nil, quarter: nil) ⇒ Time

    Parameters:

    • year (Integer) (defaults to: nil)
    • quarter (Integer) (defaults to: nil)
  • #finish_time(year: nil, season: nil) ⇒ Time

    Parameters:

    • year (Integer) (defaults to: nil)
    • season (Symbol) (defaults to: nil)
  • #finish_time(year: nil, month: nil) ⇒ Time

    Parameters:

    • year (Integer) (defaults to: nil)
    • month (Integer) (defaults to: nil)
  • #finish_time(year: nil, month: nil, day: nil) ⇒ Time

    Parameters:

    • year (Integer) (defaults to: nil)
    • month (Integer) (defaults to: nil)
    • day (Integer) (defaults to: nil)
  • #finish_time(year: nil, week: nil) ⇒ Time

    Parameters:

    • year (Integer) (defaults to: nil)
    • week (Integer) (defaults to: nil)
  • #finish_time(year: nil, day: nil) ⇒ Time

    Parameters:

    • year (Integer) (defaults to: nil)
    • day (Integer) (defaults to: nil)

Returns:

  • (Time)

See Also:



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?

Overloads:

Returns:



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?

Overloads:

Returns:



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?

Overloads:

  • #get_place(id) ⇒ Model::Place?

    Parameters:

    • id (Integer)
  • #get_place(uuid) ⇒ Model::Place?

    Parameters:

    • uuid (String)
  • #get_place(slug) ⇒ Model::Place?

    Parameters:

    • slug (String)

Returns:



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?

Returns:



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?

Returns:



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

Parameters:

Returns:



138
# File 'lib/inat-get/data/dsl/conditions/not.rb', line 138

def NOT(operand) = Condition::NOT[operand]

#NOTHINGCondition::Nothing

Returns:



192
# File 'lib/inat-get/data/dsl/conditions/base.rb', line 192

NOTHING = Condition::Nothing::instance.freeze

#nowTime

Returns:

  • (Time)


23
# File 'lib/inat-get/data/dsl/dsl.rb', line 23

def now = Time.now

#OR(*operands) ⇒ Condition::OR

Parameters:

Returns:



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

Overloads:

Returns:



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>

Overloads:

Returns:



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>

Overloads:

  • #select_observations(*ids) ⇒ Array<Model::Observation>

    Parameters:

    • ids (Array<Integer, String>)

      String for UUIDs

    Returns:

  • #select_observations(condition) ⇒ Dataset<Model::Observation>

    Parameters:

    Returns:

  • #select_observations(**query) ⇒ Dataset<Model::Observation>

    Parameters:

    • query (Hash)

    Options Hash (**query):

    • id: (Integer, Enumerable<Integer>)
    • uuid: (String, Enumerable<String>)
    • captive: (Boolean)
    • endemic: (Boolean)
    • identified: (Boolean)
    • introduced: (Boolean)
    • native: (Boolean)
    • out_of_range: (Boolean)
    • popular: (Boolean)
    • photos: (Boolean)
    • sounds: (Boolean)
    • threatened: (Boolean)
    • verifiable: (Boolean)
    • licensed: (Boolean)
    • photo_licensed: (Boolean)
    • sound_licensed: (Boolean)
    • place: (Model::Place, Enumerable<Model::Place>)
    • project: (Model::Project, Enumerable<Model::Project>)
    • taxon: (Model::Taxon, Enumerable<Model::Taxon>)
    • user: (Model::User, Enumerable<Model::User>)
    • rank: (Enum::Rank, Enumerable<Enum::Rank>, Range<Enum::Rank>)
    • observed_year: (Integer, Enumerable<Integer>)
    • observed_month: (Integer, Enumerable<Integer>)
    • observed_week: (Integer, Enumerable<Integer>)
    • observed_day: (Integer, Enumerable<Integer>)
    • observed_hour: (Integer, Enumerable<Integer>)
    • created_year: (Integer, Enumerable<Integer>)
    • created_month: (Integer, Enumerable<Integer>)
    • created_week: (Integer, Enumerable<Integer>)
    • created_day: (Integer, Enumerable<Integer>)
    • created_hour: (Integer, Enumerable<Integer>)
    • observed: (Date, Range<Time>)
    • created: (Date, Range<Time>)
    • accuracy: (Integer, nil)
    • geoprivacy: (String, Enumerable<String>)
    • taxon_geoprivacy: (String, Enumerable<String>)
    • iconic_taxa: (String, Enumerable<String>)
    • quality_grade: (String, Enumerable<String>)

    Returns:

Returns:



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>

Parameters:

  • ids (Array<Integer, String>)

Returns:



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>

Returns:



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>

Returns:



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>

Returns:



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

Overloads:

  • #start_time(date: nil) ⇒ Time

    Parameters:

    • date (Date) (defaults to: nil)
  • #start_time(century: nil) ⇒ Time

    Parameters:

    • century (Integer) (defaults to: nil)
  • #start_time(century: nil, decade: nil) ⇒ Time

    Parameters:

    • century (Integer) (defaults to: nil)
    • decade (Integer) (defaults to: nil)
  • #start_time(year: nil) ⇒ Time

    Parameters:

    • year (Integer) (defaults to: nil)
  • #start_time(year: nil, quarter: nil) ⇒ Time

    Parameters:

    • year (Integer) (defaults to: nil)
    • quarter (Integer) (defaults to: nil)
  • #start_time(year: nil, season: nil) ⇒ Time

    Parameters:

    • year (Integer) (defaults to: nil)
    • season (Symbol) (defaults to: nil)
  • #start_time(year: nil, month: nil) ⇒ Time

    Parameters:

    • year (Integer) (defaults to: nil)
    • month (Integer) (defaults to: nil)
  • #start_time(year: nil, month: nil, day: nil) ⇒ Time

    Parameters:

    • year (Integer) (defaults to: nil)
    • month (Integer) (defaults to: nil)
    • day (Integer) (defaults to: nil)
  • #start_time(year: nil, week: nil) ⇒ Time

    Parameters:

    • year (Integer) (defaults to: nil)
    • week (Integer) (defaults to: nil)
  • #start_time(year: nil, day: nil) ⇒ Time

    Parameters:

    • year (Integer) (defaults to: nil)
    • day (Integer) (defaults to: nil)

Returns:

  • (Time)

See Also:



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>

Overloads:

  • #time_range(date: nil) ⇒ Range<Time>

    Parameters:

    • date (Date) (defaults to: nil)
  • #time_range(century: nil) ⇒ Range<Time>

    Parameters:

    • century (Integer) (defaults to: nil)

      Century (20 is 1901..2000)

  • #time_range(century: nil, decade: nil) ⇒ Range<Time>

    Parameters:

    • century (Integer) (defaults to: nil)
    • decade (Integer) (defaults to: nil)
  • #time_range(year: nil) ⇒ Range<Time>

    Parameters:

    • year (Integer) (defaults to: nil)
  • #time_range(year: nil, quarter: nil) ⇒ Range<Time>

    Parameters:

    • year (Integer) (defaults to: nil)
    • quarter (Integer) (defaults to: nil)
  • #time_range(year: nil, season: nil) ⇒ Range<Time>

    Parameters:

    • year (Integer) (defaults to: nil)
    • season (Symbol) (defaults to: nil)
  • #time_range(year: nil, month: nil) ⇒ Range<Time>

    Parameters:

    • year (Integer) (defaults to: nil)
    • month (Integer) (defaults to: nil)
  • #time_range(year: nil, month: nil, day: nil) ⇒ Range<Time>

    Parameters:

    • year (Integer) (defaults to: nil)
    • month (Integer) (defaults to: nil)
    • day (Integer) (defaults to: nil)
  • #time_range(year: nil, week: nil) ⇒ Range<Time>

    Parameters:

    • year (Integer) (defaults to: nil)
    • week (Integer) (defaults to: nil)
  • #time_range(year: nil, day: nil) ⇒ Range<Time>

    Parameters:

    • year (Integer) (defaults to: nil)
    • day (Integer) (defaults to: nil)

Returns:

  • (Range<Time>)

See Also:



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

#todayDate

Returns:

  • (Date)


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

def today = Date.today

#versionGem::Version

Returns:

  • (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

Returns:

  • (true)

    or raise exception

Raises:

  • (Gem::DependencyError)


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

Returns:

  • (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_aliasString

Returns:

  • (String)


29
# File 'lib/inat-get/data/dsl/dsl.rb', line 29

def version_alias = INatGet::Info::VERSION_ALIAS