artist versions: convert other_names, url_string to arrays (#3987).

This commit is contained in:
evazion
2018-11-14 14:22:06 -06:00
parent fe2698a011
commit 741462ae68
5 changed files with 42 additions and 27 deletions

View File

@@ -174,11 +174,11 @@ class Artist < ApplicationRecord
end
def url_array
urls.map(&:to_s)
urls.map(&:to_s).sort
end
def url_string
url_array.sort.join("\n")
url_array.join("\n")
end
def url_string=(string)
@@ -275,7 +275,7 @@ class Artist < ApplicationRecord
:name => name,
:updater_id => CurrentUser.id,
:updater_ip_addr => CurrentUser.ip_addr,
:url_string => url_string,
:urls => url_array,
:is_active => is_active,
:is_banned => is_banned,
:other_names => other_names,
@@ -287,7 +287,7 @@ class Artist < ApplicationRecord
prev = versions.last
prev.update_attributes(
:name => name,
:url_string => url_string,
:urls => url_array,
:is_active => is_active,
:is_banned => is_banned,
:other_names => other_names,
@@ -306,9 +306,9 @@ class Artist < ApplicationRecord
end
self.name = version.name
self.url_string = version.url_string
self.url_string = version.urls.join("\n")
self.is_active = version.is_active
self.other_names = version.other_names
self.other_names = version.other_names.join(" ")
self.group_name = version.group_name
save
end

View File

@@ -1,4 +1,7 @@
class ArtistVersion < ApplicationRecord
array_attribute :urls
array_attribute :other_names
belongs_to_updater
belongs_to :artist
delegate :visible?, :to => :artist
@@ -47,18 +50,10 @@ class ArtistVersion < ApplicationRecord
extend SearchMethods
def url_array
url_string.to_s.split(/[[:space:]]+/)
end
def other_names_array
other_names.to_s.split(/[[:space:]]+/)
end
def urls_diff(version)
latest_urls = artist.url_array || []
new_urls = url_array
old_urls = version.present? ? version.url_array : []
new_urls = urls
old_urls = version.present? ? version.urls : []
added_urls = new_urls - old_urls
removed_urls = old_urls - new_urls
@@ -74,8 +69,8 @@ class ArtistVersion < ApplicationRecord
def other_names_diff(version)
latest_names = artist.other_names_array || []
new_names = other_names_array
old_names = version.present? ? version.other_names_array : []
new_names = other_names
old_names = version.present? ? version.other_names : []
added_names = new_names - old_names
removed_names = old_names - new_names