Class: Langulator::IndividualTranslations

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/langulator/individual_translations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ IndividualTranslations

Returns a new instance of IndividualTranslations.



6
7
8
9
10
11
# File 'lib/langulator/individual_translations.rb', line 6

def initialize(options = {})
  @aggregate_location = options[:to]
  @base_path = options[:base_path]
  @source_language = options[:source_language]
  @target_languages = options[:target_languages]
end

Instance Attribute Details

#aggregate_locationObject (readonly)

Returns the value of attribute aggregate_location.



5
6
7
# File 'lib/langulator/individual_translations.rb', line 5

def aggregate_location
  @aggregate_location
end

#base_pathObject (readonly)

Returns the value of attribute base_path.



5
6
7
# File 'lib/langulator/individual_translations.rb', line 5

def base_path
  @base_path
end

#source_languageObject (readonly)

Returns the value of attribute source_language.



5
6
7
# File 'lib/langulator/individual_translations.rb', line 5

def source_language
  @source_language
end

#target_languagesObject (readonly)

Returns the value of attribute target_languages.



5
6
7
# File 'lib/langulator/individual_translations.rb', line 5

def target_languages
  @target_languages
end

#translationsObject (readonly)

Returns the value of attribute translations.



5
6
7
# File 'lib/langulator/individual_translations.rb', line 5

def translations
  @translations
end

Instance Method Details

#<<(*objects) ⇒ Object



21
22
23
24
25
26
# File 'lib/langulator/individual_translations.rb', line 21

def <<(*objects)
  @translations ||= []
  objects.flatten.each do |obj|
    translations << obj
  end
end

#aggregateObject



48
49
50
# File 'lib/langulator/individual_translations.rb', line 48

def aggregate
  @aggregate ||= combine
end

#compileObject



17
18
19
# File 'lib/langulator/individual_translations.rb', line 17

def compile
  aggregate.write
end

#eachObject



13
14
15
# File 'lib/langulator/individual_translations.rb', line 13

def each
  translations.each { |translation| yield translation }
end

#in(*languages) ⇒ Object



28
29
30
# File 'lib/langulator/individual_translations.rb', line 28

def in(*languages)
  select {|translation| languages.include?(translation.language)}
end

#source_translationsObject



32
33
34
35
36
# File 'lib/langulator/individual_translations.rb', line 32

def source_translations
  return [] unless source_language

  self.in(source_language)
end

#target_translationsObject



38
39
40
41
42
# File 'lib/langulator/individual_translations.rb', line 38

def target_translations
  return [] unless target_languages

  self.in(*target_languages)
end