Class: ContentTypes

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby3mf/content_types.rb

Instance Method Summary collapse

Constructor Details

#initialize(found = {}, over = {}) ⇒ ContentTypes

Returns a new instance of ContentTypes.



3
4
5
6
# File 'lib/ruby3mf/content_types.rb', line 3

def initialize(found={}, over={})
  @found_types=found
  @found_overrides=over
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/ruby3mf/content_types.rb', line 12

def empty?
  size == 0
end

#get_type(target) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby3mf/content_types.rb', line 16

def get_type(target)
  target = (target.start_with?('/') ? target : '/' + target).downcase
  if @found_overrides[target]
    content_type = @found_overrides[target]
  else
    extension = File.extname(target).strip.downcase[1..-1]
    content_type = @found_types[extension]
  end
  content_type
end

#get_typesObject



27
28
29
# File 'lib/ruby3mf/content_types.rb', line 27

def get_types()
  return @found_types.values + @found_overrides.values
end

#sizeObject



8
9
10
# File 'lib/ruby3mf/content_types.rb', line 8

def size
  @found_types.size + @found_overrides.size
end