community.rb 2.21 KB
Newer Older
1
module Dspace
2
3
  class Community

4
5
    attr_accessor :name, :logo, :copyright_text,
                  :introductory_text, :short_description, :sidebar_text
6

7
8
    attr_reader :id, :handle, :type, :link, :parent_community,
                :count_items, :sub_communities, :collections, :expand
9

10
    def initialize(args={})
11
      @id = args['id'] || args['uuid']
12
      @name = args['name']
13
      @handle = args['handle']
14
      @type = args['type']
15
      @link = args['link']
16
      @logo = Dspace::Bitstream.new(args['logo']) unless args['logo'].nil?
17
      @parent_community = Dspace::Community.new(args['parentCommunity']) unless args['parentCommunity'].nil?
18
19
20
21
      @copyright_text = args['copyrightText'] || args['copyright_text']
      @introductory_text = args['introductoryText'] || args['introductory_text']
      @short_description = args['shortDescription'] || args['short_description']
      @sidebar_text = args['sidebarText'] || args['sidebar_text']
22
      @count_items = args['countItems']
23
24
25
26
27
28
29
30
31
32
33

      # subcommunities = All community endpoints
      # community = Hierarchy endpoint
      sub_communities = args['subcommunities'] || args['community']
      @sub_communities = Dspace::Builders::ModelBuilder.build_communities(sub_communities) unless sub_communities.nil?

      # collections = All community/collection endpoints
      # collection = Hierarchy endpoint
      collections = args['collections'] || args['collection']
      @collections = Dspace::Builders::ModelBuilder.build_collections(collections) unless collections.nil?

34
      @expand = args['expand']
35
36
    end

37
    def to_h
38
      {
39
          uuid: @id,
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
          name: @name,
          handle: @handle,
          type: @type,
          link: @link,
          logo: @logo,
          parentCommunity: @parent_community,
          subcommunities: obj2hash(@sub_communities),
          collections: obj2hash(@collections),
          copyrightText: @copyright_text,
          introductoryText: @introductory_text,
          shortDescription: @short_description,
          sidebarText: @sidebar_text,
          countItems: @count_items,
          expand: @expand
      }
55
56
    end

57
58
    private

59
    def obj2hash(list)
60
      Dspace::Builders::ModelBuilder.models2hash list if list.is_a? Array
61
62
    end

63
64
  end
end