Method: Hermod::XmlSectionBuilder#datetime_node
- Defined in:
- lib/hermod/xml_section_builder.rb
#datetime_node(name, options = {}) ⇒ Object
Public: defines a node for sending a datetime to HMRC
name - the name of the node. This will become the name of the method on the XmlSection. options - a hash of options used to set up validations.
Returns nothing you should rely on
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/hermod/xml_section_builder.rb', line 121 def datetime_node(name, ={}) validators = [].tap do |validators| validators << Validators::ValuePresence.new unless .delete(:optional) validators << Validators::TypeChecker.new(DateTime) { |value| value.respond_to? :strftime } end create_method(name, [], validators, ) do |value, attributes| [(value ? value.strftime(format_for(:datetime)) : nil), attributes] end end |