module Findable::ClassMethods
Public Instance Methods
find_by_name(name)
click to toggle source
# File lib/podcast_book_club/concerns/findable.rb, line 3 def find_by_name(name) self.all.detect {|i| i.name == name} end
find_by_title(title)
click to toggle source
# File lib/podcast_book_club/concerns/findable.rb, line 7 def find_by_title(title) self.all.detect {|i| i.title.downcase.include?(title.downcase)} end
find_or_create_by_name(name)
click to toggle source
# File lib/podcast_book_club/concerns/findable.rb, line 11 def find_or_create_by_name(name) instance = self.find_by_name(name) || self.create({name: name}) instance end
find_or_create_by_title(attributes)
click to toggle source
# File lib/podcast_book_club/concerns/findable.rb, line 16 def find_or_create_by_title(attributes) title = attributes[:title] if self.find_by_title(title) instance = self.find_by_title instance.episode = attributes[:episode] else self.create(attributes) end instance end