class Object

Constants

Headers
Homepage
Ver

Headers

Public Instance Methods

flatten_if_one(ary) click to toggle source

Return single item if array is full of duplicates

# File bin/musicfix, line 157
def flatten_if_one ary
    if ary.uniq.length == 1 then
        ary.first
    else
        ary.uniq
    end
end
getimages(rel) click to toggle source

Get cover artwork

# File bin/musicfix, line 82
def getimages rel
    return nil unless rel['images']
    imgs = []
    rel['images'].each do |img|
        imgs << img['uri']
    end
    imgs
end
mkartist(al) click to toggle source

Concatenate artist list using '&' Convert “Sound, The (2)” to “The Sound” Convert “Unknown (21), The” to “The Unknown”

# File bin/musicfix, line 19
def mkartist al
    nl = al.collect {|a| a['name']}
    nl.each {|n| n.gsub! /\s\(\d+\)$/, ''}
    nl.each {|n| n.gsub! /(.*), The$/, 'The \1'}
    nl.each {|n| n.gsub! /\s\(\d+\)$/, ''}
    nl.join ' & '
end
mkdiscnum(pos) click to toggle source

Convert “3” to (“”, “03”) Convert “A” to (“A”, “1”) Convert “A3” to (“A”, “3”) Convert “2.3” to (“2”, “03”) Convert “2.03” to (“2”, “03”) Convert “CD2-3” to (“2”, “03”)

# File bin/musicfix, line 33
def mkdiscnum pos
    np = pos.gsub /[-.]/, '#'
    d, n = np.split '#'
    if not n
        n = d
        d = ''
    else
        d = d.gsub /\D/, ''
    end
    parts = n.match /([A-Z])([0-9]*)/
    if parts then
        d = parts[1]
        n = parts[2] != "" && parts[2] || "1"
    else
        n = n.rjust(2, '0')
    end
    return d, n
end
mkformat(format) click to toggle source

Make a sane format string also using format description

# File bin/musicfix, line 134
def mkformat format
    f = []
    formats = []
    if format['name'] then
        formats << format['name']
    end
    if format['descriptions'] then
        formats += format['descriptions']
    end
    formats.each do |d|
        f << d if @ft.keys.include? d
    end
    f.join ' '
end
mkname(n) click to toggle source

Convert to lowercase ASCII without punctuation Convert “Jean-Michel Jarre” to “jean_michel_jarre” Convert “Aaah…!” to “aaah” Convert “Ruh / Spirit” to “ruh_spirit”

# File bin/musicfix, line 63
def mkname n
    # These may be in track titles like "(7'' Version)"
    n = n.gsub '12"', '12 inch'
    n = n.gsub "12''", "12 inch"
    n = n.gsub "12'", "12 inch"
    n = n.gsub '10"', '10 inch'
    n = n.gsub "10''", "10 inch"
    n = n.gsub "10'", "10 inch"
    n = n.gsub '7"', '7 inch'
    n = n.gsub "7''", "7 inch"
    n = n.gsub "7'", "7 inch"
    n = n.gsub " & ", " and "
    n = n.gsub '.', ' '
    n = n.gsub '/', ' '
    # Transliterate
    n.to_url.gsub '-', '_'
end
mkshort(n) click to toggle source

Shorten certain common words that appear in format strings

# File bin/musicfix, line 150
def mkshort n
    # Note that prefix substitution is broken
    ftre = /(#{@ft.keys.join('|')})/
    n.gsub(ftre, @ft)
end