Class: Fastlane::Helper::StandardMetadataBlock

Inherits:
MetadataBlock show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata_update_helper.rb,
lib/fastlane/plugin/wpmreleasetoolkit/helper/an_metadata_update_helper.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.



31
32
33
34
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata_update_helper.rb', line 31

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.



29
30
31
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata_update_helper.rb', line 29

def content_file_path
  @content_file_path
end

Instance Method Details

#generate_block(fw) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata_update_helper.rb', line 46

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

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

    # insert content
    sf = File.open(@content_file_path, 'r').to_a
    sf.each do |line|
      l = "\"#{line.strip}"
      l << '\\n' unless line == sf.last
      l << '"'
      fw.puts(l)
    end
  end

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

#handle_line(fw, line) ⇒ Object



40
41
42
43
44
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata_update_helper.rb', line 40

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

#is_handler_for(key) ⇒ Object



36
37
38
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata_update_helper.rb', line 36

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