Module: Origami::XFA::ClassMethods

Defined in:
lib/origami/xfa/xfa.rb

Instance Method Summary collapse

Instance Method Details

#mime_type(type) ⇒ Object



64
65
66
# File 'lib/origami/xfa/xfa.rb', line 64

def mime_type(type)
    define_method("mime_type") { return type }
end

#xfa_attribute(name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/origami/xfa/xfa.rb', line 31

def xfa_attribute(name)
    # Attribute getter.
    attr_getter = "attr_#{name}"
    remove_method(attr_getter) rescue NameError
    define_method(attr_getter) do
        self.attributes[name.to_s]
    end

    # Attribute setter.
    attr_setter = "attr_#{name}="
    remove_method(attr_setter) rescue NameError
    define_method(attr_setter) do |value|
        self.attributes[names.to_s] = value
    end
end

#xfa_node(name, type, _range = (0..Float::INFINITY)) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/origami/xfa/xfa.rb', line 47

def xfa_node(name, type, _range = (0..Float::INFINITY))

    adder = "add_#{name}"
    remove_method(adder) rescue NameError
    define_method(adder) do |*attr|
        elt = self.add_element(type.new)

        unless attr.empty?
            attr.first.each do |k,v|
                elt.attributes[k.to_s] = v
            end
        end

        elt
    end
end