Class: JAPR::Converter

Inherits:
Object
  • Object
show all
Extended by:
SubclassTracking
Defined in:
lib/japr/converter.rb

Overview

Base class for asset converters See github.com/janosrusiczki/japr#asset-preprocessing

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SubclassTracking

inherited, subclasses

Constructor Details

#initialize(asset) ⇒ Converter

Returns a new instance of Converter.



7
8
9
10
11
12
# File 'lib/japr/converter.rb', line 7

def initialize(asset)
  @content = asset.content
  @type = File.extname(asset.filename).downcase
  @dirname = asset.dirname
  @converted = convert
end

Instance Attribute Details

#convertedObject (readonly)

Returns the value of attribute converted.



14
15
16
# File 'lib/japr/converter.rb', line 14

def converted
  @converted
end

Class Method Details

.filetypeObject

Filetype to process (e.g. ‘.coffee’)



17
18
19
# File 'lib/japr/converter.rb', line 17

def self.filetype
  ''
end

.klass(filename) ⇒ Object

Finds a converter class based on a filename



22
23
24
25
26
# File 'lib/japr/converter.rb', line 22

def self.klass(filename)
  JAPR::Converter.subclasses.select do |c|
    c.filetype == File.extname(filename).downcase
  end.last
end

Instance Method Details

#convertObject

Logic to convert assets

Available instance variables: Returns converted string



36
37
38
# File 'lib/japr/converter.rb', line 36

def convert
  @content
end