Class: EpubForge::Utils::HtmlTranslatorQueue
- Defined in:
- lib/utils/html_translator_queue.rb
Overview
A priority stack (like a priority queue, but FILO) with a simple job: keep track of the translators (by name and by group), and return them to the object user in the order they should be tried.
Constant Summary collapse
- GROUP_NAMES =
HtmlTranslator::GROUP_NAMES
Instance Method Summary collapse
- #categorize(htmlizer) ⇒ Object
-
#each(&block) ⇒ Object
last installed, first yielded (within a given group).
-
#initialize ⇒ HtmlTranslatorQueue
constructor
A new instance of HtmlTranslatorQueue.
- #length ⇒ Object
- #named(sym) ⇒ Object
Constructor Details
#initialize ⇒ HtmlTranslatorQueue
Returns a new instance of HtmlTranslatorQueue.
10 11 12 13 14 15 16 17 |
# File 'lib/utils/html_translator_queue.rb', line 10 def initialize @translators = {} @all_translators = [] @translators_named = {} for name in GROUP_NAMES @translators[name] = [] end end |
Instance Method Details
#categorize(htmlizer) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/utils/html_translator_queue.rb', line 54 def categorize( htmlizer ) unless GROUP_NAMES.include?( htmlizer.group ) puts "No group specified for htmlizer #{htmlizer}. Group must be one of the following symbols: #{GROUP_NAMES.map(&:inspect).inspect}" return false end @all_translators << htmlizer @translators_named[htmlizer.name] = htmlizer if htmlizer.name @translators[htmlizer.group] << htmlizer end |
#each(&block) ⇒ Object
last installed, first yielded (within a given group)
Returns them in priority order, user-defined ones first. At the moment, it is up to individual translators to accept or reject the translation job based on the file format (by extension, which is lame).
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/utils/html_translator_queue.rb', line 35 def each( &block ) ordered_translators = [] for group in GROUP_NAMES.map{|g| @translators[g].reverse } ordered_translators += group end if block_given? for translator in ordered_translators yield translator end else ordered_translators.to_enum end end |
#length ⇒ Object
50 51 52 |
# File 'lib/utils/html_translator_queue.rb', line 50 def length @all_translators.length end |
#named(sym) ⇒ Object
65 66 67 |
# File 'lib/utils/html_translator_queue.rb', line 65 def named( sym ) @translators_named[sym] end |