Method: Hermod::XmlSectionBuilder#date_node

Defined in:
lib/hermod/xml_section_builder.rb

#date_node(name, options = {}) ⇒ Object

Public: defines a node for sending a date 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



104
105
106
107
108
109
110
111
112
113
# File 'lib/hermod/xml_section_builder.rb', line 104

def date_node(name, options={})
  validators = [].tap do |validators|
    validators << Validators::ValuePresence.new unless options.delete(:optional)
    validators << Validators::TypeChecker.new(Date) { |value| value.respond_to? :strftime }
  end

  create_method(name, [], validators, options) do |value, attributes|
    [(value ? value.strftime(format_for(:date)) : nil), attributes]
  end
end