Method: Milkode::Cdstk#sorted_plangs

Defined in:
lib/milkode/cdstk/cdstk.rb

#sorted_plangs(records) ⇒ Object



865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
# File 'lib/milkode/cdstk/cdstk.rb', line 865

def sorted_plangs(records)
  total = {}
  
  records.each do |record|
    lang = PlangDetector.new(record.restpath)

    if total[lang.name]
      total[lang.name] += 1
    else
      total[lang.name] = 1
    end
  end

  total.map {|name, count|
    [name, count]
  }.sort {|a, b|
    if (a[0] == PlangDetector::UNKNOWN)
      -1
    elsif (b[0] == PlangDetector::UNKNOWN)
      1
    else
      a[1] <=> b[1]
    end
  }.reverse
end