Created
June 7, 2017 15:31
-
-
Save awead/45c15e78381c60804db7e2aef06ac802 to your computer and use it in GitHub Desktop.
Fixing mis-ordered fifles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reports on and fixes mis-ordered titles. | |
# To run, download the raw output of the array of works with multiple titles. Open the file | |
# in a text editor and add "@@titles = " to the beginning of the line to set the array as | |
# class variable. Save the file as titles.rb and upload it to the temp directory of the server. | |
# | |
# From the Rails console, copy and paste in the code below. Run the report and fix the works. | |
# A possible sequence would be: | |
# | |
# > report = TitleOrder.new | |
# > report.misordered_titles | |
# > report.results.count | |
# => 179 | |
# > report.fix | |
# > report.misordered_titles | |
# > report.results.count | |
# => 0 | |
# --------------------------------------------------------------------------------------------- | |
require '/tmp/titles' | |
class TitleOrder | |
attr_reader :report, :results | |
def initialize | |
@report = @@titles | |
end | |
# @return [Array<Hash>] reports of works that have a different title order | |
def misordered_titles | |
@results = [] | |
report.each do |h| | |
work = GenericWork.find(h.fetch("id")) | |
next if work.title == h.fetch("title_tesim") | |
@results << h | |
end | |
@results | |
end | |
def fix | |
results.each do |h| | |
work = GenericWork.find(h.fetch("id")) | |
work.title = h.fetch("title_tesim") | |
work.save | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment