Sha256: 670188792be12f77e57c9e22113924eaaa4a0298ab43d2e29db1c971941f39c0

Contents?: true

Size: 768 Bytes

Versions: 4

Compression:

Stored size: 768 Bytes

Contents

module Findable
    module ClassMethods
        def find_by_name(name)
            self.all.detect {|i| i.name == name}
        end

        def find_by_title(title)
            self.all.detect {|i| i.title.downcase.include?(title.downcase)}
        end

        def find_or_create_by_name(name)
            instance = self.find_by_name(name) || self.create({name: name})
            instance
        end

        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

    end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
podcast-book-club-1.0.3 lib/podcast_book_club/concerns/findable.rb
podcast-book-club-1.0.2 lib/podcast_book_club/concerns/findable.rb
podcast-book-club-1.0.1 lib/podcast_book_club/concerns/findable.rb
podcast-book-club-1.0.0 lib/podcast_book_club/concerns/findable.rb