move repeated build method from entities for HashBuilder module

parent d694a60b
module Dspace
class Bitstream
include Dspace::Builders::HashBuilder
attr_accessor :name, :bundle_name,
:description, :format, :mime_type
......
......@@ -2,13 +2,19 @@ module Dspace
module Builders
module HashBuilder
def obj2hash(list)
self.class.models2hash list
end
def self.models2hash(list)
hash = []
list.each do |m|
hash << m.to_h
end
if list.is_a? Array
hash = []
list.each do |m|
hash << m.to_h
end
hash
hash
end
end
end
......
......@@ -62,6 +62,9 @@ module Dspace
def connection_options
{
url: @dspace_api || DSPACE_API,
ssl: {
verify: false
},
headers: {
content_type: 'application/json',
'rest-dspace-token' => access_token.to_s,
......
module Dspace
class Collection
include Dspace::Builders::HashBuilder
attr_accessor :name, :logo, :license, :copyright_text,
:introductory_text, :short_description, :sidebar_text
......@@ -49,11 +50,5 @@ module Dspace
}
end
private
def obj2hash(list)
Dspace::Builders::HashBuilder.models2hash list
end
end
end
\ No newline at end of file
......@@ -20,8 +20,8 @@ module Dspace
@short_description = args['shortDescription']
@sidebar_text = args['sidebarText']
@count_items = args['countItems']
@sub_communities = Dspace::Builders::ModelBuilder.build_communities(args['subcommunities'])
@collections = Dspace::Builders::ModelBuilder.build_collections(args['collections'])
@sub_communities = Dspace::Builders::ModelBuilder.build_communities(args['subcommunities']) unless args['subcommunities'].nil?
@collections = Dspace::Builders::ModelBuilder.build_collections(args['collections']) unless args['collections'].nil?
@expand = args['expand']
end
......@@ -48,7 +48,7 @@ module Dspace
private
def obj2hash(list)
Dspace::Builders::HashBuilder.models2hash list
Dspace::Builders::HashBuilder.models2hash list if list.is_a? Array
end
end
......
module Dspace
class Item
include Dspace::Builders::HashBuilder
attr_accessor :name, :archived, :withdrawn
......@@ -57,11 +58,5 @@ module Dspace
@metadata = []
end
private
def obj2hash(list)
Dspace::Builders::HashBuilder.models2hash list
end
end
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment