Class: Translatomatic::TextCollection
- Inherits:
-
Object
- Object
- Translatomatic::TextCollection
- Defined in:
- lib/translatomatic/text_collection.rb
Overview
A collection of texts
Instance Attribute Summary collapse
-
#originals ⇒ Object
readonly
Returns the value of attribute originals.
Instance Method Summary collapse
-
#count ⇒ Number
The total number of texts in the collection, equal to the number of sentences and context strings.
-
#each_locale ⇒ Object
Iterate over texts in the collection grouped by locale.
-
#initialize(texts = []) ⇒ TextCollection
constructor
A new instance of TextCollection.
Constructor Details
#initialize(texts = []) ⇒ TextCollection
Returns a new instance of TextCollection.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/translatomatic/text_collection.rb', line 6 def initialize(texts = []) texts = [texts] unless texts.is_a?(Array) texts = texts.select { |i| translatable?(i) } texts = textify(texts) # convert to Text objects @originals = texts @sentences = find_sentences(texts) # convert to sentences contexts = find_contexts(texts) @all_texts = @sentences + contexts group_by_locale(@all_texts) end |
Instance Attribute Details
#originals ⇒ Object (readonly)
Returns the value of attribute originals.
4 5 6 |
# File 'lib/translatomatic/text_collection.rb', line 4 def originals @originals end |
Instance Method Details
#count ⇒ Number
Returns The total number of texts in the collection, equal to the number of sentences and context strings.
26 27 28 |
# File 'lib/translatomatic/text_collection.rb', line 26 def count @all_texts.length end |
#each_locale ⇒ Object
Iterate over texts in the collection grouped by locale
18 19 20 21 22 |
# File 'lib/translatomatic/text_collection.rb', line 18 def each_locale @by_locale.each do |locale, list| yield locale, list end end |