Class: Translatomatic::TextCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/translatomatic/text_collection.rb

Overview

A collection of texts

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#originalsObject (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

#countNumber

Returns The total number of texts in the collection, equal to the number of sentences and context strings.

Returns:

  • (Number)

    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_localeObject

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