Class: Fastlane::Helper::StandardMetadataBlock

Inherits:
MetadataBlock show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/standard_metadata_block.rb

Instance Attribute Summary collapse

Attributes inherited from MetadataBlock

#block_key

Instance Method Summary collapse

Constructor Details

#initialize(block_key, content_file_path) ⇒ StandardMetadataBlock

Returns a new instance of StandardMetadataBlock.



8
9
10
11
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/standard_metadata_block.rb', line 8

def initialize(block_key, content_file_path)
  super(block_key)
  @content_file_path = content_file_path
end

Instance Attribute Details

#content_file_pathObject (readonly)

Returns the value of attribute content_file_path.



6
7
8
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/standard_metadata_block.rb', line 6

def content_file_path
  @content_file_path
end

Instance Method Details

#generate_block(file) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/standard_metadata_block.rb', line 23

def generate_block(file)
  # init
  file.puts("msgctxt \"#{@block_key}\"")
  line_count = File.foreach(@content_file_path).inject(0) { |c, _line| c + 1 }

  if line_count <= 1
    # Single line output
    file.puts("msgid \"#{File.read(@content_file_path).rstrip}\"")
  else
    # Multiple line output
    file.puts('msgid ""')

    # insert content
    File.open(@content_file_path, 'r').each do |line|
      file.puts("\"#{line.strip}\\n\"")
    end
  end

  # close
  file.puts('msgstr ""')
  file.puts('')
end

#handle_line(file, line) ⇒ Object



17
18
19
20
21
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/standard_metadata_block.rb', line 17

def handle_line(file, line)
  # put the new content on block start
  # and skip all the other content
  generate_block(file) if line.start_with?('msgctxt')
end

#is_handler_for(key) ⇒ Object



13
14
15
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/standard_metadata_block.rb', line 13

def is_handler_for(key)
  key == @block_key.to_s
end