Skip to content

Commit

Permalink
break out tags to its own class
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed Aug 28, 2018
1 parent 88f3122 commit 3ec2198
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions .rubocop_todo.yml
Expand Up @@ -278,6 +278,7 @@ Style/Documentation:
- 'app/controllers/versions_controller.rb'
- 'app/controllers/workflows_controller.rb'
- 'app/models/dor/goobi.rb'
- 'app/models/dor/goobi_tag.rb'
- 'app/models/dor/registration_response.rb'
- 'app/models/dor/service_item.rb'
- 'app/models/dor/update_marc_record_service.rb'
Expand Down
4 changes: 2 additions & 2 deletions app/models/dor/goobi.rb
Expand Up @@ -16,8 +16,8 @@ def register
end

def goobi_xml_tags
goobi_tag_list.map do |tag_name, tag_value|
"<tag name=\"#{tag_name}\" value=\"#{tag_value}\"></tag>"
goobi_tag_list.map do |tag|
"<tag name=\"#{tag.name}\" value=\"#{tag.value}\"></tag>"
end.join
end

Expand Down
10 changes: 10 additions & 0 deletions app/models/dor/goobi_tag.rb
@@ -0,0 +1,10 @@
module Dor
class GoobiTag
attr_accessor :name, :value

def initialize(p_hash)
@name = p_hash[:name]
@value = p_hash[:value]
end
end
end
4 changes: 2 additions & 2 deletions app/models/dor/service_item.rb
Expand Up @@ -115,11 +115,11 @@ def goobi_ocr_tag_present?

# returns an array of arrays, each element contains an array of [name, value] of DOR object tags in the format expected to pass to Goobi
# the name of the tag is the first namespace part of the tag (before first colon), value of the tag is everything after this
# @return [Array] of arrays, each element is a [name, value] pair of tags derived from the DOR object, e.g. [['Tag1', 'Value1'], ['Tag2', 'Value2']]
# @return [Array] of GoobiTag objects
def goobi_tag_list
@druid_obj.tags.map do |tag|
tag_split = tag.split(':', 2).map(&:strip) # only split on the first colon
[tag_split[0], tag_split[1]]
GoobiTag.new(name: tag_split[0], value: tag_split[1])
end
end
end
Expand Down
11 changes: 9 additions & 2 deletions spec/service_item_spec.rb
Expand Up @@ -49,7 +49,11 @@

it 'returns an array of arrays with the tags from the object in the key:value format expected to be passed to goobi' do
allow(@dor_item).to receive(:tags).and_return(['DPG : Workflow : book_workflow', 'Process : Content Type : Book (flipbook, ltr)', 'LAB : Map Work'])
expect(@si.goobi_tag_list).to eq([['DPG', 'Workflow : book_workflow'], ['Process', 'Content Type : Book (flipbook, ltr)'], ['LAB', 'Map Work']])
expect(@si.goobi_tag_list.length).to eq 3
@si.goobi_tag_list.each { |goobi_tag| expect(goobi_tag.class).to eq Dor::GoobiTag }
expect(@si.goobi_tag_list[0]).to have_attributes(name: 'DPG', value: 'Workflow : book_workflow')
expect(@si.goobi_tag_list[1]).to have_attributes(name: 'Process', value: 'Content Type : Book (flipbook, ltr)')
expect(@si.goobi_tag_list[2]).to have_attributes(name: 'LAB', value: 'Map Work')
end

it 'returns an empty array when there are no tags' do
Expand All @@ -59,7 +63,10 @@

it 'works with singleton tags (no colon, so no value, just a name)' do
allow(@dor_item).to receive(:tags).and_return(['Name : Some Value', 'JustName'])
expect(@si.goobi_tag_list).to eq([['Name', 'Some Value'], ['JustName', nil]])
expect(@si.goobi_tag_list.length).to eq 2
expect(@si.goobi_tag_list[0].class).to eq Dor::GoobiTag
expect(@si.goobi_tag_list[0]).to have_attributes(name: 'Name', value: 'Some Value')
expect(@si.goobi_tag_list[1]).to have_attributes(name: 'JustName', value: nil)
end
end

Expand Down

0 comments on commit 3ec2198

Please sign in to comment.