Class: Rosette::Core::StaticExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/rosette/core/extractor/static_extractor.rb

Overview

Base class for extractors that extract entries from flat files, eg. XML, YAML, json, etc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ StaticExtractor

Creates a new extractor.

Parameters:

  • config (Configurator) (defaults to: nil)

    The Rosette config to use.


17
18
19
# File 'lib/rosette/core/extractor/static_extractor.rb', line 17

def initialize(config = nil)
  @config = config
end

Instance Attribute Details

#configConfigurator (readonly)

Returns the Rosette config to use.

Returns:


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rosette/core/extractor/static_extractor.rb', line 11

class StaticExtractor
  attr_reader :config

  # Creates a new extractor.
  #
  # @param [Configurator] config The Rosette config to use.
  def initialize(config = nil)
    @config = config
  end

  # Extracts each translatable phrase from the given flat file
  # contents. Must be implemented by derived classes
  #
  # @param [String] file_contents The flat file contents to extract
  #   phrases from.
  # @return [void, Enumerator] If passed a block, this method yields
  #   each consecutive phrase found in +file_contents+. If no block is
  #   passed, it returns an +Enumerator+.
  # @yield [phrase] a single extracted phrase.
  # @yieldparam phrase [Phrase]
  def extract_each_from(file_contents)
    raise NotImplementedError,
      "#{__method__} must be implemented by derived classes."
  end

  protected

  def make_phrase(key, meta_key = nil, file = nil)
    Phrase.new(key, meta_key, file)
  end
end

Instance Method Details

#extract_each_from(file_contents) {|phrase| ... } ⇒ void, Enumerator

Extracts each translatable phrase from the given flat file contents. Must be implemented by derived classes

Parameters:

  • file_contents (String)

    The flat file contents to extract phrases from.

Yields:

  • (phrase)

    a single extracted phrase.

Yield Parameters:

Returns:

  • (void, Enumerator)

    If passed a block, this method yields each consecutive phrase found in file_contents. If no block is passed, it returns an Enumerator.

Raises:

  • (NotImplementedError)

31
32
33
34
# File 'lib/rosette/core/extractor/static_extractor.rb', line 31

def extract_each_from(file_contents)
  raise NotImplementedError,
    "#{__method__} must be implemented by derived classes."
end