Module: PoAndXliffConsolidator::FileHandle

Includes:
Logging
Included in:
Combine, Extract
Defined in:
lib/po_and_xliff_consolidator/file_handle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, logger, #logger, logger=

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



9
10
11
# File 'lib/po_and_xliff_consolidator/file_handle.rb', line 9

def app_name
  @app_name
end

#path_templatesObject

Returns the value of attribute path_templates.



7
8
9
# File 'lib/po_and_xliff_consolidator/file_handle.rb', line 7

def path_templates
  @path_templates
end

#root_file_pathObject

Returns the value of attribute root_file_path.



8
9
10
# File 'lib/po_and_xliff_consolidator/file_handle.rb', line 8

def root_file_path
  @root_file_path
end

Instance Method Details

#combined_file_nameObject



30
31
32
# File 'lib/po_and_xliff_consolidator/file_handle.rb', line 30

def combined_file_name
  get_path(path_templates[:combined])
end

#get_path(path_array) ⇒ Object



26
27
28
# File 'lib/po_and_xliff_consolidator/file_handle.rb', line 26

def get_path(path_array)
  File.join(path_array.map{|p| p.gsub('%{root_file_path}',@root_file_path).gsub('%{language_code}',@language_code).gsub('%{xliff_language_code}',@xliff_language_code).gsub('%{app_name}',@app_name)})
end

#initializeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/po_and_xliff_consolidator/file_handle.rb', line 11

def initialize
  @path_templates = {
      need_translating: {
          po: ['%{root_file_path}','web-app','need-translating','locales','%{language_code}','%{app_name}.po'],
          xliff: ['%{root_file_path}','xliff','need-translating','%{xliff_language_code}.xliff']
      },
      translated: {
          po: ['%{root_file_path}','web-app','translated','locales','%{language_code}','%{app_name}.po'],
          xliff: ['%{root_file_path}','xliff','translated','%{xliff_language_code}.xliff'],
      },
      combined: ['%{root_file_path}','combined','%{language_code}.po']
  }
  super
end

#web_app_file_pointer(subfolder, mode) ⇒ Object



42
43
44
45
46
# File 'lib/po_and_xliff_consolidator/file_handle.rb', line 42

def web_app_file_pointer(subfolder, mode)
  fn = web_app_filename(subfolder)
  logger.debug "Opening #{fn}"
  File.open(fn, mode)
end

#web_app_filename(subfolder) ⇒ Object



34
35
36
# File 'lib/po_and_xliff_consolidator/file_handle.rb', line 34

def web_app_filename(subfolder)
  get_path(path_templates[subfolder][:po])
end

#xcode_doc(subfolder) ⇒ Object



48
49
50
51
52
# File 'lib/po_and_xliff_consolidator/file_handle.rb', line 48

def xcode_doc(subfolder)
  fn = xcode_file_name(subfolder)
  logger.debug "Opening #{fn}"
  Nokogiri.XML(File.open(fn))
end

#xcode_file_name(subfolder) ⇒ Object



38
39
40
# File 'lib/po_and_xliff_consolidator/file_handle.rb', line 38

def xcode_file_name(subfolder)
  get_path(path_templates[subfolder][:xliff])
end