Class: INatGet::Data::Helper::Field::Rank Private

Inherits:
Set show all
Defined in:
lib/inat-get/data/helpers/defs/rank.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary

Attributes inherited from INatGet::Data::Helper::Field

#helper, #key

Instance Method Summary collapse

Constructor Details

#initialize(helper, key) ⇒ Rank

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Rank.



8
9
10
# File 'lib/inat-get/data/helpers/defs/rank.rb', line 8

def initialize helper, key
  super helper, key, INatGet::Data::Enum::Rank
end

Instance Method Details

#prepare(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/inat-get/data/helpers/defs/rank.rb', line 20

def prepare value
  if value.is_a?(::Range)
    # b = value.begin || INatGet::Data::Enum::Rank.first
    # e = value.end   || INatGet::Data::Enum::Rank.last
    # (b..e).to_a.to_set
    # { :rank_level => (value.begin&.level .. value.end&.level) }
    value
  else
    super value
  end
end

#to_api(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/inat-get/data/helpers/defs/rank.rb', line 32

def to_api value
  # value.map(&:to_s)
  if value.is_a?(::Range)
    result = {}
    result[:lrank] = value.begin.to_s if value.begin
    result[:hrank] = value.end.to_s   if value.end
    result
  else
    value
  end
end

#to_sequel(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/inat-get/data/helpers/defs/rank.rb', line 44

def to_sequel value
  cond = case value
  when ::Range
    { rank_level: (value.begin&.level .. value.end&.level) }
  when Enumerable
    { rank: value.map(&:to_s) }
  when INatGet::Data::Enum::Rank
    { rank: value.to_s }
  else
    { rank: value }
  end
  if self.helper.endpoint == :observations
    require_relative '../../models/taxon'
    { taxon_id: INatGet::Data::Model::Taxon.where(cond).select(:id) }
  else
    cond
  end
end

#valid?(value) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


12
13
14
15
16
17
18
# File 'lib/inat-get/data/helpers/defs/rank.rb', line 12

def valid? value
  if value.is_a?(::Range)
    (value.begin.nil? || value.begin.is_a?(INatGet::Data::Enum::Rank)) && (value.end.nil? || value.end.is_a?(INatGet::Data::Enum::Rank))
  else
    super value
  end
end