Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

break out tags to its own class #140

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could even add a to_xml method here which would return:

        "<tag name=\"#{name}\" value=\"#{value}\"></tag>"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, i'm going to push to this branch and then submit a new PR against master (since the goobi-tag work is now merged)

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