Class: XMLRegistryObjects
- Inherits:
-
Object
- Object
- XMLRegistryObjects
- Defined in:
- lib/xmlregistry_objects.rb
Instance Attribute Summary collapse
-
#to_h ⇒ Object
readonly
Returns the value of attribute to_h.
Instance Method Summary collapse
- #define_methods ⇒ Object
-
#initialize(reg, polyrexdoc) ⇒ XMLRegistryObjects
constructor
A new instance of XMLRegistryObjects.
Constructor Details
#initialize(reg, polyrexdoc) ⇒ XMLRegistryObjects
Returns a new instance of XMLRegistryObjects.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/xmlregistry_objects.rb', line 14 def initialize(reg, polyrexdoc) @to_h = polyrexdoc.records.inject({}) do |rtn, row| name, path = row.name, row.regkey[1..-2] class_name = name.capitalize klass = Object.const_set(class_name,Class.new) s = " def initialize(reg) @reg = reg end " s = if row.records.any? then row.records.inject(s) do |r, attr| attr_name, subkey = attr.name, attr.subkeyname r << make_def(path, subkey, attr_name) end else names = reg.xpath("#{path}/*/name()") names.inject(s) do |r, subkey| r << make_def(path, subkey) end end klass.class_eval s rtn.merge name.to_sym => klass.new(reg) end end |
Instance Attribute Details
#to_h ⇒ Object (readonly)
Returns the value of attribute to_h.
12 13 14 |
# File 'lib/xmlregistry_objects.rb', line 12 def to_h @to_h end |
Instance Method Details
#define_methods ⇒ Object
53 54 55 |
# File 'lib/xmlregistry_objects.rb', line 53 def define_methods() @to_h.each.map {|k,v| "define_method :#{k.to_s}, ->{h[:#{k}]}"}.join("\n") end |