Class: Fastlane::Helper::WhatsNewMetadataBlock

Inherits:
StandardMetadataBlock show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/whats_new_metadata_block.rb

Instance Attribute Summary collapse

Attributes inherited from StandardMetadataBlock

#content_file_path

Attributes inherited from MetadataBlock

#block_key

Instance Method Summary collapse

Constructor Details

#initialize(block_key, content_file_path, release_version) ⇒ WhatsNewMetadataBlock

Returns a new instance of WhatsNewMetadataBlock.



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

def initialize(block_key, content_file_path, release_version)
  super(block_key, content_file_path)
  @rel_note_key = 'whats_new'
  @release_version = release_version
  generate_keys(release_version)
end

Instance Attribute Details

#new_keyObject (readonly)

Returns the value of attribute new_key.



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

def new_key
  @new_key
end

#old_keyObject (readonly)

Returns the value of attribute old_key.



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

def old_key
  @old_key
end

#rel_note_keyObject (readonly)

Returns the value of attribute rel_note_key.



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

def rel_note_key
  @rel_note_key
end

#release_versionObject (readonly)

Returns the value of attribute release_version.



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

def release_version
  @release_version
end

Instance Method Details

#generate_block(file) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/whats_new_metadata_block.rb', line 37

def generate_block(file)
  # init
  file.puts("msgctxt \"#{@new_key}\"")
  file.puts('msgid ""')

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

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

#generate_keys(release_version) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/whats_new_metadata_block.rb', line 15

def generate_keys(release_version)
  values = release_version.split('.')
  version_major = Integer(values[0])
  version_minor = Integer(values[1])
  @new_key = "v#{release_version}-whats-new"

  version_major -= 1 if version_minor.zero?
  version_minor = version_minor.zero? ? 9 : version_minor - 1

  @old_key = "v#{version_major}.#{version_minor}-whats-new"
end

#handle_line(file, line) ⇒ Object



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

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

#is_handler_for(key) ⇒ Object



27
28
29
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/whats_new_metadata_block.rb', line 27

def is_handler_for(key)
  key.start_with?('v') && key.end_with?('-whats-new')
end