Class: Yuzu::Translators::Translator

Inherits:
Register
  • Object
show all
Defined in:
lib/yuzu/translators/base.rb

Direct Known Subclasses

MarkdownTranslator, PlaintextTranslator

Constant Summary collapse

@@translators =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.can_translate?(website_file) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
# File 'lib/yuzu/translators/base.rb', line 24

def self.can_translate?(website_file)
  source_extension = website_file.path.extension
  # TODO map source -> output extensions, e.g. haml-to-xml, etc.
  #target_extension = website_file.extension
  filetype = identify_filetype(source_extension)
  not filetype.nil?
end

.filetypesObject



39
40
41
# File 'lib/yuzu/translators/base.rb', line 39

def self.filetypes
  Translator.translators.keys
end

.identify_filetype(file_extension) ⇒ Object



32
33
34
35
36
37
# File 'lib/yuzu/translators/base.rb', line 32

def self.identify_filetype(file_extension)
  Translator.translators.each_pair do |filetype, translator|
    return filetype if translator.translates?(file_extension)
  end
  return nil
end

.registryObject



8
9
10
# File 'lib/yuzu/translators/base.rb', line 8

def self.registry
  :translators
end

.translate(contents, file_extension) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/yuzu/translators/base.rb', line 15

def self.translate(contents, file_extension)
  filetype = identify_filetype(file_extension)
  if not filetype.nil?
    Translator.translators[filetype].translate(contents)
  else
    contents
  end
end

.translatorsObject



11
12
13
# File 'lib/yuzu/translators/base.rb', line 11

def self.translators
  @@translators
end

Instance Method Details

#extensionsObject



47
48
49
# File 'lib/yuzu/translators/base.rb', line 47

def extensions
  []
end

#translate(contents) ⇒ Object



51
52
53
# File 'lib/yuzu/translators/base.rb', line 51

def translate(contents)
  contents
end

#translates?(file_extension) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/yuzu/translators/base.rb', line 43

def translates?(file_extension)
  extensions.include?(file_extension)
end