Class: INatGet::Data::Helper::Field::Ids Private
- Inherits:
-
INatGet::Data::Helper::Field
- Object
- INatGet::Data::Helper::Field
- INatGet::Data::Helper::Field::Ids
- Defined in:
- lib/inat-get/data/helpers/defs/ids.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
Instance Method Summary collapse
-
#initialize(helper, key) ⇒ Ids
constructor
private
A new instance of Ids.
- #prepare(value) ⇒ Object private
- #to_sequel(value) ⇒ Object private
- #valid?(value) ⇒ Boolean private
Methods inherited from INatGet::Data::Helper::Field
Constructor Details
#initialize(helper, key) ⇒ Ids
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 Ids.
7 8 9 |
# File 'lib/inat-get/data/helpers/defs/ids.rb', line 7 def initialize helper, key super helper, key 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.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/inat-get/data/helpers/defs/ids.rb', line 11 def prepare value case value when nil nil when Integer, String ::Set[ value ] when Enumerable value.to_set else raise ArgumentError, "Invalid field value: #{ @key } => #{ value.inspect }", caller_locations 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.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/inat-get/data/helpers/defs/ids.rb', line 43 def to_sequel value return {} if value.nil? @sid ||= helper.manager.sid @uuid ||= helper.manager.uuid? result = [] value.each do |v| result << { id: v } if v.is_a?(Integer) result << { uuid: v } if @uuid && v.is_a?(String) && v =~ INatGet::Data::Helper::UUID_PATTERN result << { @sid.to_sym => v } if @sid && v.is_a?(String) end Sequel.|(*result) 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.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/inat-get/data/helpers/defs/ids.rb', line 24 def valid? value @sid ||= helper.manager.sid @uuid ||= helper.manager.uuid? return true if value.nil? return true if value.is_a?(Integer) return true if @sid && value.is_a?(String) return true if @uuid && value.is_a?(String) && value =~ INatGet::Data::Helper::UUID_PATTERN if value.is_a?(Enumerable) value.each do |v| next if v.is_a?(Integer) next if @sid && v.is_a?(String) next if @uuid && v.is_a?(String) && v =~ INatGet::Data::Helper::UUID_PATTERN return false end return true end return false end |