model_builder.rb 1.55 KB
Newer Older
1
module Dspace
Mateus Rambo Strey's avatar
Mateus Rambo Strey committed
2
3
4
5
  module Builders
    module ModelBuilder

      def self.build_communities(communities=[])
6
        return communities unless communities.is_a? Array
Mateus Rambo Strey's avatar
Mateus Rambo Strey committed
7
8
        colls = []
        communities.each do |c|
9
          colls << Dspace::Community.new(c)
Mateus Rambo Strey's avatar
Mateus Rambo Strey committed
10
11
12
13
14
        end
        colls
      end

      def self.build_collections(collections=[])
15
        return collections unless collections.is_a? Array
Mateus Rambo Strey's avatar
Mateus Rambo Strey committed
16
17
        colls = []
        collections.each do |c|
18
          colls << Dspace::Collection.new(c)
Mateus Rambo Strey's avatar
Mateus Rambo Strey committed
19
20
21
22
23
        end
        colls
      end

      def self.build_items(items=[])
24
        return items unless items.is_a? Array
Mateus Rambo Strey's avatar
Mateus Rambo Strey committed
25
26
        colls = []
        items.each do |c|
27
          colls << Dspace::Item.new(c)
Mateus Rambo Strey's avatar
Mateus Rambo Strey committed
28
29
30
31
32
        end
        colls
      end

      def self.build_bitstreams(bitstreams=[])
33
        return bitstreams unless bitstreams.is_a? Array
Mateus Rambo Strey's avatar
Mateus Rambo Strey committed
34
35
        colls = []
        bitstreams.each do |c|
36
          colls << Dspace::Bitstream.new(c)
Mateus Rambo Strey's avatar
Mateus Rambo Strey committed
37
38
39
40
41
        end
        colls
      end

      def self.build_metadatas(metadatas=[])
42
        return metadatas unless metadatas.is_a? Array
Mateus Rambo Strey's avatar
Mateus Rambo Strey committed
43
44
        colls = []
        metadatas.each do |c|
45
          colls << Dspace::Metadata.new(c)
Mateus Rambo Strey's avatar
Mateus Rambo Strey committed
46
47
48
49
50
        end
        colls
      end

      def self.build_policies(policies=[])
51
        return policies unless policies.is_a? Array
Mateus Rambo Strey's avatar
Mateus Rambo Strey committed
52
53
        colls = []
        policies.each do |c|
54
          colls << Dspace::Policy.new(c)
Mateus Rambo Strey's avatar
Mateus Rambo Strey committed
55
56
57
58
        end
        colls
      end

59
60
61
62
63
64
65
66
      def self.models2hash(list)
        if list.is_a? Array
          list.map do |m|
            m.to_h
          end
        end
      end

Mateus Rambo Strey's avatar
Mateus Rambo Strey committed
67
68
69
    end
  end
end