Sha256: 18cd0f2a6723dac7bede939d4525512f709ff4dc65d539f71127b38524f593d5

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

module MusicBrainz
  class ReleaseGroup < BaseModel
    field :id, String
    field :type, String
    field :title, String
    field :desc, String
    field :first_release_date, Date

    alias_method :disambiguation, :desc

    def releases
      @releases ||= client.load(:release, { release_group: id, inc: [:media, :release_groups], limit: 100 }, {
        binding: :release_group_releases,
        create_models: :release,
        sort: :date
      }) unless @id.nil?
    end

    class << self
      def find(id)
        client.load(:release_group, { id: id }, {
          binding: :release_group,
          create_model: :release_group
        })
      end
      
      def search(artist_name, title, options = {})
        artist_name = CGI.escape(artist_name).gsub(/\!/, '\!')
        title = CGI.escape(title).gsub(/\!/, '\!')
        query = ["artist:\"#{artist_name}\"", "releasegroup:\"#{title}\""]
        query << "type: #{options[:type]}" if options[:type]

        client.load(
          :release_group, { query: query.join(' AND '), limit: 10 }, 
          { binding: :release_group_search }
        )
      end
      
      def find_by_artist_and_title(artist_name, title, options = {})
        matches = search(artist_name, title, options)
        matches.empty? ? nil : find(matches.first[:id])
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
musicbrainz-0.7.4 lib/musicbrainz/models/release_group.rb