Class: FindStrKey::GenReport

Inherits:
Object
  • Object
show all
Defined in:
lib/applocale/Core/FindStrKey/find_str_key_result.rb

Constant Summary collapse

DEFAULT_XLSX =
'findkey_result.xlsx'
DEFAULT_TXT =
'findkey_result.txt'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proj_path, path, main_result, second_result) ⇒ GenReport

Returns a new instance of GenReport.



14
15
16
17
18
19
# File 'lib/applocale/Core/FindStrKey/find_str_key_result.rb', line 14

def initialize(proj_path, path, main_result, second_result)
  self.proj_path = proj_path
  self.path = path
  self.main_result = main_result
  self.second_result = second_result
end

Instance Attribute Details

#main_resultObject

Returns the value of attribute main_result.



12
13
14
# File 'lib/applocale/Core/FindStrKey/find_str_key_result.rb', line 12

def main_result
  @main_result
end

#pathObject

Returns the value of attribute path.



12
13
14
# File 'lib/applocale/Core/FindStrKey/find_str_key_result.rb', line 12

def path
  @path
end

#proj_pathObject

Returns the value of attribute proj_path.



12
13
14
# File 'lib/applocale/Core/FindStrKey/find_str_key_result.rb', line 12

def proj_path
  @proj_path
end

#second_resultObject

Returns the value of attribute second_result.



12
13
14
# File 'lib/applocale/Core/FindStrKey/find_str_key_result.rb', line 12

def second_result
  @second_result
end

Instance Method Details

#gen_txtObject



49
50
51
52
53
# File 'lib/applocale/Core/FindStrKey/find_str_key_result.rb', line 49

def gen_txt
  txt_path = File.join(self.path, DEFAULT_TXT)
  File.delete(txt_path) if File.exist? txt_path
  self.write_to_txt(txt_path)
end

#gen_xlsxObject



21
22
23
24
25
# File 'lib/applocale/Core/FindStrKey/find_str_key_result.rb', line 21

def gen_xlsx
  xlsx_path = File.join(self.path, DEFAULT_XLSX)
  File.delete(xlsx_path) if File.exist? xlsx_path
  self.write_to_xlsx(xlsx_path)
end

#write_to_txt(txt_path) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/applocale/Core/FindStrKey/find_str_key_result.rb', line 55

def write_to_txt(txt_path)
  puts "Start write to file: \"#{txt_path}\" ...".green
  target = open(txt_path, 'w')

  self.main_result.each do |arrs|
    key = arrs.first.value
    target.puts("#{key} : ")
    arrs.each do |obj|
      rpath = Pathname.new(obj.file).relative_path_from(Pathname.new(self.proj_path)).to_s
      target.puts("   line-#{obj.line}:\t#{rpath}")
    end
    target.puts('')
  end
  target.close
end

#write_to_xlsx(xlsx_path) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/applocale/Core/FindStrKey/find_str_key_result.rb', line 27

def write_to_xlsx(xlsx_path)
  puts "Start write to file: \"#{xlsx_path}\" ...".green
  workbook = RubyXL::Workbook.new
  worksheet = workbook.worksheets[0]
  rowno = 0
  keycolno = 0
  self.main_result.each do |arrs|
    key = arrs.first.value
    worksheet.add_cell(rowno, keycolno, key)
    rowno += 1
  end
  worksheet.add_cell(rowno, 0, '')
  worksheet.change_row_fill(rowno, 'fffacd')
  rowno += 1
  self.second_result.each do |arrs|
    key = arrs.first.value
    worksheet.add_cell(rowno, keycolno, key)
    rowno += 1
  end
  workbook.write(xlsx_path)
end