Class: Ecoportal::API::V2::Page::Component::DateField
- Inherits:
-
Ecoportal::API::V2::Page::Component
- Object
- Common::BaseModel
- Common::Content::DoubleModel
- Ecoportal::API::V2::Page::Component
- Ecoportal::API::V2::Page::Component::DateField
- Defined in:
- lib/ecoportal/api/v2/page/component/date_field.rb
Constant Summary collapse
- ISO8601 =
'%Y-%m-%dT%H:%M:00.00Z'
'%Y-%m-%dT%H:%M:00Z'.freeze
Constants included from Common::Content::StringDigest
Common::Content::StringDigest::MAX_HASH_LABEL
Constants included from Common::Content::DoubleModel::Diffable
Common::Content::DoubleModel::Diffable::DIFF_CLASS
Constants included from Common::Content::DoubleModel::Base
Common::Content::DoubleModel::Base::NOT_USED
Instance Attribute Summary
Attributes included from Common::Content::DoubleModel::Parented
Instance Method Summary collapse
-
#configure(*conf) ⇒ Object
Quick config helper.
- #create_event=(value) ⇒ Object
- #empty? ⇒ Boolean
- #to_s ⇒ Object
- #value ⇒ Object
- #value=(val) ⇒ Object
Methods inherited from Ecoportal::API::V2::Page::Component
#attached?, #bindings, #bindings?, #delete!, #forces, get_class, #indexable_label, #move, #multi_section?, new_doc, #ooze, #ref, #ref_backend, #replace, #replace_bindings, #section, #unattach!
Methods included from Common::Content::StringDigest
Methods inherited from Common::Content::DoubleModel
Methods included from Common::Content::DoubleModel::Diffable
Methods included from Common::Content::Includer
Constructor Details
This class inherits a constructor from Ecoportal::API::Common::Content::DoubleModel
Instance Method Details
#configure(*conf) ⇒ Object
Quick config helper
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ecoportal/api/v2/page/component/date_field.rb', line 60 def configure(*conf) conf.each_with_object([]) do |cnf, unused| case cnf when :time self.show_time = true when :now_button self. = true when :past self.past_only = true when :event self.create_event = true when Hash supported = [:reminder] unless (rest = hash_except!(cnf.dup, *supported)).empty? unused.push(rest) end configure_reminder(cnf[:reminder]) if cnf.key?(:reminder) else unused.push(cnf) end end.then do |unused| super(*unused) end end |
#create_event=(value) ⇒ Object
36 37 38 39 |
# File 'lib/ecoportal/api/v2/page/component/date_field.rb', line 36 def create_event=(value) self.past_only = false doc['create_event'] = !!value end |
#empty? ⇒ Boolean
17 18 19 |
# File 'lib/ecoportal/api/v2/page/component/date_field.rb', line 17 def empty? !value end |
#to_s ⇒ Object
41 42 43 44 45 |
# File 'lib/ecoportal/api/v2/page/component/date_field.rb', line 41 def to_s return unless value to_local_time(value).strftime(ISO8601) end |
#value ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/ecoportal/api/v2/page/component/date_field.rb', line 28 def value if (val = doc['value']) (Time.parse(val) rescue nil).then do |datetime| # rubocop:disable Style/RescueModifier datetime&.localtime end end end |
#value=(val) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/ecoportal/api/v2/page/component/date_field.rb', line 21 def value=(val) doc['value'] = self.class.to_time(val).then do |datetime| datetime = datetime.utc.strftime(ISO8601) if datetime datetime end end |