Class: RestfulSharePoint::CommonBase
- Inherits:
-
Object
- Object
- RestfulSharePoint::CommonBase
- Defined in:
- lib/restful-sharepoint/common-base.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#objectify(tree) ⇒ Object
Converts the given enumerable tree to a collection or object.
Instance Method Details
#objectify(tree) ⇒ Object
Converts the given enumerable tree to a collection or object.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/restful-sharepoint/common-base.rb', line 4 def objectify(tree) klass = nil if tree['results'] && !tree['results'].empty? if type = tree.dig('__metadata', 'type') || tree.dig('results', 0, '__metadata', 'type') pattern, klass = COLLECTION_MAP.find { |pattern,| pattern.match(type) } end klass ? RestfulSharePoint.const_get(klass).new(parent: self, collection: tree['results']) : tree['results'] elsif tree['__metadata'] if type = tree['__metadata']['type'] pattern, klass = OBJECT_MAP.find { |pattern,| pattern.match(type) } end klass ? RestfulSharePoint.const_get(klass).new(parent: self, properties: tree) : tree end end |