Class: Muxml::Base::Relation::Many
- Inherits:
-
Object
- Object
- Muxml::Base::Relation::Many
- Includes:
- Enumerable
- Defined in:
- lib/muxml/relation.rb
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(obj, relation, options = {}) ⇒ Many
constructor
A new instance of Many.
Constructor Details
#initialize(obj, relation, options = {}) ⇒ Many
Returns a new instance of Many.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/muxml/relation.rb', line 34 def initialize(obj, relation, = {}) @obj = obj @relation = relation @tag = .delete(:tag) || relation @class_name = .delete(:class_name) @query = .delete(:select) @options = raise ArgumentError, "#{obj.class.to_s} :class_name is nil" if @class_name.nil? raise ArgumentError, "#{obj.class.to_s} :tag is nil" if @tag.nil? unless @query.nil? attributes = @query.map{|k,v| "@#{k}='#{v}'"}.join @find_query = "#{@tag}[#{attributes}]" else @find_query = "#{@tag}" end end |
Instance Method Details
#each ⇒ Object
53 54 55 56 57 |
# File 'lib/muxml/relation.rb', line 53 def each @obj.xml.elements.each("#{@find_query}") { |element| yield Object.const_get(@class_name).new(element) } end |