Module: SGE::JobHelpers::ClassMethods
- Defined in:
- lib/sge/job_helpers.rb
Instance Method Summary collapse
- #attributes_path ⇒ Object
- #define_attributes(opts) ⇒ Object
- #from_document(doc) ⇒ Object
- #special_attribute(a, path) ⇒ Object
Instance Method Details
#attributes_path ⇒ Object
31 32 33 |
# File 'lib/sge/job_helpers.rb', line 31 def attributes_path @attributes_path ||= @attributes.join('|') end |
#define_attributes(opts) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sge/job_helpers.rb', line 14 def define_attributes(opts) opts.each do |k,v| @attributes.push(k) attr_accessor(v) alias_method k, v alias_method "#{k}=", "#{v}=" end # If attributes changed reload attributes_path @attributes_path = nil @attributes end |
#from_document(doc) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sge/job_helpers.rb', line 36 def from_document(doc) instance = new doc.xpath('.//' + self.attributes_path ).each do |node| instance.send("#{node.name}=", node.text) end @special_attributes.each do |k,v| doc.xpath('.//' + v.to_s) instance.send("#{k}=", doc.xpath('.//' + v.to_s).map{ |n| n.text}) end instance end |
#special_attribute(a, path) ⇒ Object
26 27 28 29 |
# File 'lib/sge/job_helpers.rb', line 26 def special_attribute(a, path) attr_accessor a @special_attributes[a] = path end |