Class: Salad::CatalogueOfLife

Inherits:
Object
  • Object
show all
Defined in:
lib/salad/catalogue_of_life.rb

Overview

Wraps Colrapi so calls are scoped to a Catalogue of Life dataset by default. Users override by passing dataset_id explicitly — as a positional arg for methods that take it positionally, or as a kwarg otherwise.

Constant Summary collapse

DEFAULT_DATASET_ID =
'3LR'

Instance Method Summary collapse

Constructor Details

#initialize(mod = Colrapi) ⇒ CatalogueOfLife

Returns a new instance of CatalogueOfLife.



10
11
12
# File 'lib/salad/catalogue_of_life.rb', line 10

def initialize(mod = Colrapi)
  @mod = mod
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwargs, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/salad/catalogue_of_life.rb', line 14

def method_missing(name, *args, **kwargs, &block)
  return super unless @mod.respond_to?(name)

  ds_param = @mod.method(name).parameters.find { |_, pname| pname == :dataset_id }

  if ds_param
    case ds_param[0]
    when :req
      args = [DEFAULT_DATASET_ID] if args.empty?
    when :key, :keyreq
      kwargs[:dataset_id] = DEFAULT_DATASET_ID unless kwargs.key?(:dataset_id)
    end
  end

  @mod.public_send(name, *args, **kwargs, &block)
end

Instance Method Details

#inspectObject



39
40
41
# File 'lib/salad/catalogue_of_life.rb', line 39

def inspect
  "#<Salad::CatalogueOfLife(default dataset_id=#{DEFAULT_DATASET_ID})>"
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/salad/catalogue_of_life.rb', line 31

def respond_to_missing?(name, include_private = false)
  @mod.respond_to?(name, include_private) || super
end

#to_sObject



35
36
37
# File 'lib/salad/catalogue_of_life.rb', line 35

def to_s
  @mod.to_s
end