lib/cts/mpx/entries.rb in cts-mpx-1.0.3 vs lib/cts/mpx/entries.rb in cts-mpx-1.1.0
- old
+ new
@@ -9,23 +9,10 @@
include Creatable
extend Forwardable
attribute name: 'collection', kind_of: Array
- # Create a new entries collection from a page
- # @param [Page] page the page object to process
- # @raise [ArgumentError] if :page is not available
- # @return [Entries] a new entries collection
- def self.create_from_page(page)
- Exceptions.raise_unless_argument_error? page, Page
- entries = page.entries.each do |e|
- entry = Entry.create(fields: Fields.create_from_data(data: e, xmlns: page.xmlns))
- entry.id = entry.fields['id'] if entry.fields['id']
- end
- Entries.create(collection: entries)
- end
-
# Addressable method, indexed by entry object
# @param [Entry] key the entry to return
# @return [Self.collection,Entry,nil] Can return the collection, a single entry, or nil if nothing found
def [](key = nil)
return @collection unless key
@@ -79,10 +66,16 @@
end
# A hash of all available entries
# @return [Hash]
def to_h
- map(&:to_h)
+ output = { xmlns: {}, entries: [] }
+
+ each do |entry|
+ output[:entries].push entry.to_h[:entry]
+ output[:xmlns].merge! entry.fields.xmlns
+ end
+ output
end
end
end
end