Class: MML::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mml.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Base



8
9
10
11
12
# File 'lib/mml.rb', line 8

def initialize(args = {})
  args.keys.each do |item|
    send "#{item.to_s}=", args[item]
  end
end

Class Method Details

.mandatory_attribute(*attrs) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mml.rb', line 21

def mandatory_attribute(*attrs)
  attrs.each do |attr|
    class_eval %{
      attr_reader attr
      
      def #{attr}=(value)
        raise ArgumentError, '#{attr} is mandatory' if value.nil?
        @#{attr}=value
      end
    }
  end
end

Instance Method Details

#namespaceObject



14
15
16
# File 'lib/mml.rb', line 14

def namespace
  MML_NAMESPACE
end

#to_xmlObject



35
36
37
38
# File 'lib/mml.rb', line 35

def to_xml
  xml = Builder::XmlMarkup.new
  eval xml_builder
end