Class: Cardiac::Representation::Reflection

Inherits:
Struct
  • Object
show all
Defined in:
lib/cardiac/representation.rb

Overview

Basic reflection of a representation type.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(extension, default_type = nil, *extra_types) ⇒ Reflection

Returns a new instance of Reflection.



37
38
39
40
41
42
43
44
45
# File 'lib/cardiac/representation.rb', line 37

def initialize(extension,default_type=nil,*extra_types)
  types = __codecs__.mimes_for(extension) + extra_types
  if default_type.nil?
    default_type = types.first
  elsif ! types.include? default_type
    types.unshift default_type
  end
  super extension.to_sym, types, default_type, __codecs__.coder_for(extension)
end

Instance Attribute Details

#coderObject

Returns the value of attribute coder

Returns:

  • (Object)

    the current value of coder



36
37
38
# File 'lib/cardiac/representation.rb', line 36

def coder
  @coder
end

#default_typeObject

Returns the value of attribute default_type

Returns:

  • (Object)

    the current value of default_type



36
37
38
# File 'lib/cardiac/representation.rb', line 36

def default_type
  @default_type
end

#extensionObject

Returns the value of attribute extension

Returns:

  • (Object)

    the current value of extension



36
37
38
# File 'lib/cardiac/representation.rb', line 36

def extension
  @extension
end

#typesObject

Returns the value of attribute types

Returns:

  • (Object)

    the current value of types



36
37
38
# File 'lib/cardiac/representation.rb', line 36

def types
  @types
end

Instance Method Details

#__codecs__Object



54
55
56
# File 'lib/cardiac/representation.rb', line 54

def __codecs__
  @__codecs__ ||= ::Cardiac::Representation::Codecs
end

#matches?(mime_type) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/cardiac/representation.rb', line 50

def matches?(mime_type)
  types.any?{|type| type.like? mime_type}
end