Class: INatGet::Data::Helper::Field::Period Private
- Inherits:
-
Range
- Object
- INatGet::Data::Helper::Field
- Range
- INatGet::Data::Helper::Field::Period
- Defined in:
- lib/inat-get/data/helpers/defs/period.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) ⇒ Period
constructor
private
A new instance of Period.
- #prepare(value) ⇒ Object private
- #to_api(value) ⇒ Object private
- #valid?(value) ⇒ Boolean private
- #value_begin(value) ⇒ Object private private
- #value_end(value) ⇒ Object private private
- #value_exclude(value) ⇒ Object private private
Methods inherited from INatGet::Data::Helper::Field
Constructor Details
#initialize(helper, key) ⇒ Period
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 Period.
9 10 11 |
# File 'lib/inat-get/data/helpers/defs/period.rb', line 9 def initialize helper, key super helper, key, Time 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.
21 22 23 24 |
# File 'lib/inat-get/data/helpers/defs/period.rb', line 21 def prepare value #(value_begin(value) .. value_end(value)) ::Range::new(value_begin(value), value_end(value), value_exclude(value)) 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.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/inat-get/data/helpers/defs/period.rb', line 26 def to_api value result = {} case @key when :observed result[:d1] = value.begin if value.begin result[:d2] = value.end if value.end when :created result[:created_d1] = value.begin if value.begin result[:created_d2] = value.end if value.end end 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.
13 14 15 16 17 18 19 |
# File 'lib/inat-get/data/helpers/defs/period.rb', line 13 def valid? value value.is_a?(Time) || value.is_a?(Date) || value.is_a?(::Range) && (value.begin.nil? || value.begin.is_a?(Time) || value.begin.is_a?(Date)) && (value.end.nil? || value.end.is_a?(Time) || value.end.is_a?(Date)) end |
#value_begin(value) ⇒ Object (private)
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.
41 42 43 44 45 |
# File 'lib/inat-get/data/helpers/defs/period.rb', line 41 def value_begin value value = value.begin if value.is_a?(::Range) value = value.to_time if value.is_a?(Date) value end |
#value_end(value) ⇒ Object (private)
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.
47 48 49 50 51 |
# File 'lib/inat-get/data/helpers/defs/period.rb', line 47 def value_end value value = value.end if value.is_a?(::Range) value = (value + 1).to_time if value.is_a?(Date) value end |
#value_exclude(value) ⇒ Object (private)
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.
53 54 55 56 57 |
# File 'lib/inat-get/data/helpers/defs/period.rb', line 53 def value_exclude value value = value.exclude_end? if value.is_a?(::Range) # value = true if value.is_a?(Date) || value.is_a(Time) !!value end |