Method: Hermod::XmlSectionBuilder#monetary_node
- Defined in:
- lib/hermod/xml_section_builder.rb
#monetary_node(name, options = {}) ⇒ Object
Public: defines a node for sending a monetary value 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
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/hermod/xml_section_builder.rb', line 164 def monetary_node(name, ={}) validators = [].tap do |validators| validators << Validators::NonNegative.new unless .fetch(:negative, true) validators << Validators::NonZero.new unless .fetch(:zero, true) validators << Validators::WholeUnits.new if [:whole_units] end create_method(name, [], validators, ) do |value, attributes| value ||= value.to_i if [:optional] && value == 0 [nil, attributes] else [sprintf(format_for(:money), value), attributes] end end end |