Method: Hermod::XmlSectionBuilder#string_node

Defined in:
lib/hermod/xml_section_builder.rb

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

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



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/hermod/xml_section_builder.rb', line 66

def string_node(name, options={})
  mutators = [].tap do |mutators|
    mutators << InputMutator.new(options.delete(:input_mutator)) if options.has_key? :input_mutator
  end
  validators = [].tap do |validators|
    validators << Validators::AllowedValues.new(options.delete(:allowed_values)) if options.has_key? :allowed_values
    validators << Validators::RegularExpression.new(options.delete(:matches)) if options.has_key? :matches
    validators << Validators::ValuePresence.new unless options.delete(:optional)
    validators << Validators::Attributes.new(options.fetch(:attributes, {}).keys)
  end
  create_method(name, mutators, validators, options) do |value, attributes|
    [value, attributes]
  end
end