mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-04 15:01:48 +01:00
small refactorings
This commit is contained in:
parent
7d0c716366
commit
82bb67f518
6 changed files with 61 additions and 130 deletions
|
|
@ -62,24 +62,26 @@ module IsTaggable
|
|||
outgoing = tag_cast_to_string(outgoing)
|
||||
tags.delete(*(tags.select{|tag| outgoing.include? tag.name}))
|
||||
end
|
||||
|
||||
def get_tag_name_from_item(item)
|
||||
case item
|
||||
# removed next line as it prevents using numbers as tags
|
||||
# when /^\d+$/, Fixnum then Tag.find(item).name # This will be slow if you use ids a lot.
|
||||
when Tag
|
||||
item.name
|
||||
when String
|
||||
item
|
||||
else
|
||||
raise "Invalid type"
|
||||
end
|
||||
end
|
||||
|
||||
def tag_cast_to_string obj
|
||||
case obj
|
||||
when Array
|
||||
obj.map! do |item|
|
||||
case item
|
||||
# removed next line as it prevents using numbers as tags
|
||||
# when /^\d+$/, Fixnum then Tag.find(item).name # This will be slow if you use ids a lot.
|
||||
when Tag then item.name
|
||||
when String then item
|
||||
else
|
||||
raise "Invalid type"
|
||||
end
|
||||
end
|
||||
obj.map! { |item| get_tag_name_from_item(item) }
|
||||
when String
|
||||
obj = obj.split(Tag::DELIMITER).map do |tag_name|
|
||||
tag_name.strip.squeeze(" ")
|
||||
end
|
||||
obj.split(Tag::DELIMITER).map { |tag_name| tag_name.strip.squeeze(" ") }
|
||||
else
|
||||
raise "Invalid object of class #{obj.class} as tagging method parameter"
|
||||
end.flatten.compact.map(&:downcase).uniq
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue