Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7886789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:24:34+00:00 2026-06-03T05:24:34+00:00

Sample hash: { audio => { audio/aac => [aac], audio/mpeg => [mp3, mp2], audio/mp4

  • 0

Sample hash:

  {
    "audio" =>  {
      "audio/aac" => ["aac"],
      "audio/mpeg" => ["mp3", "mp2"],
      "audio/mp4" => ["m4a", "m4b", "m4r", "3gp"],
      "audio/ogg" => ["ogg", "oga"],
      "audio/flac" => ["flac"],
      "audio/speex" => ["spx"],
      "audio/x-ms-wma" => ["wma"],
      "audio/x-pn-realaudio" => ["rm", "ram"],
      "audio/vnd.wave" => ["wav"],
      "audio/x-musepack" => ["mpc", "mp+", "mpp"],
      "audio/x-aiff" => ["aiff", "aif", "aifc"],
      "audio/x-tta" => ["tta"]
    },
    "video" =>  {
      "video/mp4" => ["mp4"],
      "video/mpeg" => ["mpg", "mpeg"],
      "video/x-m4v" => ["m4v"],
      "video/quicktime" => ["mov"],
      "video/x-msvideo" => ["avi"],
      "video/x-flv" => ["flv"],
      "video/webm" => ["webm"]
    }
  }

What’s the best way given a file extension to get the associated content type (first match is okay)?

Searching for “flac” should return “audio/flac”.

Currently I’m using this:

hsh.each_key do |group|
  hsh[group].each do |k,v|
    return k if v.include?(extension)
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:24:36+00:00Added an answer on June 3, 2026 at 5:24 am

    Unraveling that sort of structure is best done when it’s created. But, you can loop through the various levels and get something useful from it. If I assign your initial hash to mime_hash I can unravel it using:

    Hash[*mime_hash.map{ |av, types| types.map{ |mime_type, extensions| extensions.product([mime_type]) } }.flatten] 
    

    or more verbosely:

    Hash[
      *mime_hash.map{ |av, types| 
        types.map{ |mime_type, extensions| 
          extensions.product([mime_type]) 
        } 
      }.flatten
    ] 
    

    Which will return:

    {
         "aac" => "audio/aac",
         "mp3" => "audio/mpeg",
         "mp2" => "audio/mpeg",
         "m4a" => "audio/mp4",
         "m4b" => "audio/mp4",
         "m4r" => "audio/mp4",
         "3gp" => "audio/mp4",
         "ogg" => "audio/ogg",
         "oga" => "audio/ogg",
        "flac" => "audio/flac",
         "spx" => "audio/speex",
         "wma" => "audio/x-ms-wma",
          "rm" => "audio/x-pn-realaudio",
         "ram" => "audio/x-pn-realaudio",
         "wav" => "audio/vnd.wave",
         "mpc" => "audio/x-musepack",
         "mp+" => "audio/x-musepack",
         "mpp" => "audio/x-musepack",
        "aiff" => "audio/x-aiff",
         "aif" => "audio/x-aiff",
        "aifc" => "audio/x-aiff",
         "tta" => "audio/x-tta",
         "mp4" => "video/mp4",
         "mpg" => "video/mpeg",
        "mpeg" => "video/mpeg",
         "m4v" => "video/x-m4v",
         "mov" => "video/quicktime",
         "avi" => "video/x-msvideo",
         "flv" => "video/x-flv",
        "webm" => "video/webm"
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sample application which generates a SHA1 hash in PHP as follows.
In my Ruby application I have a hash table: c = {:sample => 1,:another
This is sample PHP code I made to hash a string. Does this method
From this sample code from MSDN http://msdn.microsoft.com/en-us/library/system.string.gethashcode.aspx The hash code for abc is: 536991770
I'm trying to include a simple hash table class in some files with a
I have written a simple Java class to generate the hash values of the
I am using Perl with XML::Simple to convert a hash into an XML document.
I'm writing a simple content management system. I need to store SHA1 hash values
I'm looking to create a simple brute-force password-cracker which will hash an input from
Sample Data: 603 Some garbage data not related to me, 55, 113 -> 1-ENST0000

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.