Module: RubyLLM::MimeType

Defined in:
lib/ruby_llm/mime_type.rb

Overview

MimeTypes module provides methods to handle MIME types using Marcel gem

Constant Summary collapse

TEXT_SUFFIXES =

MIME types that have a text/ prefix but need to be handled differently

['+json', '+xml', '+html', '+yaml', '+csv', '+plain', '+javascript', '+svg'].freeze
NON_TEXT_PREFIX_TEXT_MIME_TYPES =

MIME types that don’t have a text/ prefix but should be treated as text

[
  'application/json', # Base type, even if specific ones end with +json
  'application/xml',  # Base type, even if specific ones end with +xml
  'application/javascript',
  'application/ecmascript',
  'application/rtf',
  'application/sql',
  'application/x-sh',
  'application/x-csh',
  'application/x-httpd-php',
  'application/sdp',
  'application/sparql-query',
  'application/graphql',
  'application/yang', # Data modeling language, often serialized as XML/JSON but the type itself is distinct
  'application/mbox', # Mailbox format
  'application/x-tex',
  'application/x-latex',
  'application/x-perl',
  'application/x-python',
  'application/x-tcl',
  'application/pgp-signature', # Often ASCII armored
  'application/pgp-keys',      # Often ASCII armored
  'application/vnd.coffeescript',
  'application/vnd.dart',
  'application/vnd.oai.openapi', # Base for OpenAPI, often with +json or +yaml suffix
  'application/vnd.zul',         # ZK User Interface Language (can be XML-like)
  'application/x-yaml',          # Common non-standard for YAML
  'application/yaml',            # Standard for YAML
  'application/toml'             # TOML configuration files
].freeze

Class Method Summary collapse

Class Method Details

.audio?(type) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/ruby_llm/mime_type.rb', line 22

def audio?(type)
  type.start_with?('audio/')
end

.forObject



10
11
12
# File 'lib/ruby_llm/mime_type.rb', line 10

def for(...)
  Marcel::MimeType.for(...)
end

.image?(type) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/ruby_llm/mime_type.rb', line 14

def image?(type)
  type.start_with?('image/')
end

.pdf?(type) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ruby_llm/mime_type.rb', line 26

def pdf?(type)
  type == 'application/pdf'
end

.text?(type) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/ruby_llm/mime_type.rb', line 30

def text?(type)
  type.start_with?('text/') ||
    TEXT_SUFFIXES.any? { |suffix| type.end_with?(suffix) } ||
    NON_TEXT_PREFIX_TEXT_MIME_TYPES.include?(type)
end

.video?(type) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/ruby_llm/mime_type.rb', line 18

def video?(type)
  type.start_with?('video/')
end