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.



9
10
11
12
13
14
# File 'lib/japr/converter.rb', line 9

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.



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

def converted
  @converted
end

Class Method Details

.filetypeObject

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



19
20
21
# File 'lib/japr/converter.rb', line 19

def self.filetype
  ''
end

.klass(filename) ⇒ Object

Finds a converter class based on a filename



24
25
26
27
28
# File 'lib/japr/converter.rb', line 24

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



38
39
40
# File 'lib/japr/converter.rb', line 38

def convert
  @content
end