class MetalArchives::Band

Represents an band (person or group)

Attributes

aliases[R]

Returns Array of String

Raises
comment[R]

Returns raw HTML String

Raises
country[R]

Returns ISO3166::Country

Raises
date_active[R]

Returns Array of Range containing NilDate

Raises
date_formed[R]

Returns NilDate

Raises
genres[R]

Returns Array of String

Raises
id[R]

Returns Integer

independent[R]

Returns boolean

Raises
label[R]

Returns Label

Raises
location[R]

Returns String

Raises
lyrical_themes[R]

Returns Array of String

Raises
name[R]

Returns String

Raises
photo[R]

Returns URI (rewritten if config option was enabled)

Raises
releases[R]

Returns Array of Release

Raises
similar[R]

Returns Array of Hash containing the following keys

Raises
similar
  • :band: Band

  • :score: Integer

status[R]

Returns :active, :split_up, :on_hold, :unknown, :changed_name or :disputed

Raises

Protected Class Methods

all() click to toggle source

Get all bands

Returns Collection of Band

Raises
# File lib/metal_archives/models/band.rb, line 454
def all
  search_by({})
end
find(id) click to toggle source

Find by ID

Returns Band, even when ID is invalid (because the data is lazily fetched)

id

Integer

# File lib/metal_archives/models/band.rb, line 269
def find(id)
  return cache[id] if cache.include? id

  Band.new id: id
end
find!(id) click to toggle source

Find by ID (no lazy loading)

Returns Band

Raises
id

Integer

# File lib/metal_archives/models/band.rb, line 288
def find!(id)
  obj = find id
  obj.load! if obj && !obj.loaded?

  obj
end
find_by(query) click to toggle source

Find by attributes

Refer to MA’s FAQ for search tips.

Returns Band or nil when no results

Raises
query

Hash containing one or more of the following keys:

  • :name: String

  • :exact: Boolean

  • :genre: String

  • :country: ISO3166::Country

  • :year_formation: Range containing NilDate

  • :comment: String

  • :status: see Band.status

  • :lyrical_themes: String

  • :location: String

  • :label: Label

  • :independent: boolean

# File lib/metal_archives/models/band.rb, line 320
def find_by(query)
  url = "#{MetalArchives.config.default_endpoint}search/ajax-advanced/searching/bands"
  params = Parsers::Band.map_params query

  response = HTTPClient.get url, params
  json = JSON.parse response.body

  return nil if json["aaData"].empty?

  data = json["aaData"].first
  id = Nokogiri::HTML(data.first).xpath("//a/@href").first.value.delete('\\').split("/").last.gsub(/\D/, "").to_i

  find id
end
find_by!(query) click to toggle source

Find by attributes (no lazy loading)

Refer to MA’s FAQ for search tips.

Returns Band or nil when no results

Raises
query

Hash containing one or more of the following keys:

  • :name: String

  • :exact: Boolean

  • :genre: String

  • :country: ISO3166::Country

  • :year_formation: Range containing NilDate

  • :comment: String

  • :status: see Band.status

  • :lyrical_themes: String

  • :location: String

  • :label: Label

  • :independent: boolean

# File lib/metal_archives/models/band.rb, line 360
def find_by!(query)
  obj = find_by query
  obj.load! if obj && !obj.loaded?

  obj
end
search_by(query) click to toggle source

Search by attributes

Refer to MA’s FAQ for search tips.

Returns Collection of Band

Raises
query

Hash containing one or more of the following keys:

  • :name: String

  • :exact: Boolean

  • :genre: String

  • :country: ISO3166::Country

  • :year_formation: Range containing NilDate

  • :comment: String

  • :status: see Band.status

  • :lyrical_themes: String

  • :location: String

  • :label: Label

  • :independent: boolean

# File lib/metal_archives/models/band.rb, line 392
def search_by(query)
  url = "#{MetalArchives.config.default_endpoint}search/ajax-advanced/searching/bands"

  params = Parsers::Band.map_params query

  l = lambda do
    @start ||= 0

    if @max_items && @start >= @max_items
      []
    else
      response = HTTPClient.get url, params.merge(iDisplayStart: @start)
      json = JSON.parse response.body

      @max_items = json["iTotalRecords"]

      objects = []

      json["aaData"].each do |data|
        # Create Band object for every ID in the results list
        id = Nokogiri::HTML(data.first).xpath("//a/@href").first.value.delete('\\').split("/").last.gsub(/\D/, "").to_i
        objects << Band.find(id)
      end

      @start += 200

      objects
    end
  end

  MetalArchives::Collection.new l
end