Class: GettextSimpleRails::SetupHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/gettext_simple_rails/setup_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ SetupHelper

Returns a new instance of SetupHelper.



2
3
4
# File 'lib/gettext_simple_rails/setup_helper.rb', line 2

def initialize(args = {})
  @args = args
end

Instance Method Details

#poedit_add_ruby_parser_to_configObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/gettext_simple_rails/setup_helper.rb', line 19

def poedit_add_ruby_parser_to_config
  sample_path = "#{File.dirname(__FILE__)}/../../config/poedit_ruby_parser.conf"
  sample_content = File.read(sample_path).strip
  config_content = File.read(poedit_config_path).strip
  
  File.open(poedit_config_path, "w") do |fp|
    fp.puts(config_content)
    fp.puts(sample_content)
  end
end

#poedit_config_add_ruby_to_list_of_parsersObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gettext_simple_rails/setup_helper.rb', line 37

def poedit_config_add_ruby_to_list_of_parsers
  config_content = File.read(poedit_config_path).strip
  parsers_list_match = config_content.match(/\[Parsers\]\s+List=(.+?)\n/)
  list = parsers_list_match[1].split(";")
  list << "Ruby"
  
  new_config = config_content.gsub(parsers_list_match[0], "[Parsers]\nList=#{list.join(";")}\n")
  raise "Could not add Ruby to list of parsers." if new_config == config_content
  
  File.open(poedit_config_path, "w") do |fp|
    fp.puts(new_config)
  end
end

#poedit_config_has_ruby_in_list_of_parsers?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
# File 'lib/gettext_simple_rails/setup_helper.rb', line 30

def poedit_config_has_ruby_in_list_of_parsers?
  config_content = File.read(poedit_config_path).strip
  parsers_list_match = config_content.match(/\[Parsers\]\s+List=(.+?)\n/)
  list = parsers_list_match[1].split(";")
  return list.include?("Ruby")
end

#poedit_config_has_ruby_parser?Boolean

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/gettext_simple_rails/setup_helper.rb', line 14

def poedit_config_has_ruby_parser?
  config_content = File.read(poedit_config_path)
  return config_content.include?("[Parsers/Ruby]")
end

#poedit_config_pathObject



6
7
8
9
10
11
12
# File 'lib/gettext_simple_rails/setup_helper.rb', line 6

def poedit_config_path
  if @args[:poedit_config_path]
    return @args[:poedit_config_path]
  else
    "#{ENV["HOME"]}/.poedit/config"
  end
end