Class: Deliver::Loader::LanguageFolder

Inherits:
Object
  • Object
show all
Defined in:
deliver/lib/deliver/loader.rb

Overview

A class that represents language folder under screenshots or metadata folder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, nested: false) ⇒ LanguageFolder

Returns a new instance of LanguageFolder.

Parameters:

  • path (String)

    A directory path otherwise this initializer fails

  • nested (Boolan) (defaults to: false)

    Whether given path is nested of another special directory. This affects ‘expandable?` to return `false` when this set to `true`.

Raises:

  • (ArgumentError)


45
46
47
48
49
50
# File 'deliver/lib/deliver/loader.rb', line 45

def initialize(path, nested: false)
  raise(ArgumentError, "Given path must be a directory path - #{path}") unless File.directory?(path)
  @path = path
  @language = self.class.available_languages.find { |lang| basename.casecmp?(lang) }
  @nested = nested
end

Instance Attribute Details

#languageString (readonly)

Returns A normalized language name that corresponds to the directory’s name.

Returns:

  • (String)

    A normalized language name that corresponds to the directory’s name



30
31
32
# File 'deliver/lib/deliver/loader.rb', line 30

def language
  @language
end

#pathObject (readonly)

Returns the value of attribute path.



27
28
29
# File 'deliver/lib/deliver/loader.rb', line 27

def path
  @path
end

Class Method Details

.allowed_directory_names_with_caseObject



38
39
40
# File 'deliver/lib/deliver/loader.rb', line 38

def self.allowed_directory_names_with_case
  available_languages + SPECIAL_DIR_NAMES
end

.available_languagesObject



32
33
34
35
36
# File 'deliver/lib/deliver/loader.rb', line 32

def self.available_languages
  # 2020-08-24 - Available locales are not available as an endpoint in App Store Connect
  # Update with Spaceship::Tunes.client.available_languages.sort (as long as endpoint is avilable)
  Deliver::Languages::ALL_LANGUAGES
end

Instance Method Details

#basenameObject



76
77
78
# File 'deliver/lib/deliver/loader.rb', line 76

def basename
  File.basename(@path)
end

#expandable?Boolean

Returns:



60
61
62
# File 'deliver/lib/deliver/loader.rb', line 60

def expandable?
  !nested? && EXPANDABLE_DIR_NAMES.any? { |name| name.casecmp?(basename) }
end

#file_paths(extensions = '{png,jpg,jpeg}') ⇒ Object



68
69
70
# File 'deliver/lib/deliver/loader.rb', line 68

def file_paths(extensions = '{png,jpg,jpeg}')
  Dir.glob(File.join(path, "*.#{extensions}"), File::FNM_CASEFOLD).sort
end

#framed_file_paths(extensions = '{png,jpg,jpeg}') ⇒ Object



72
73
74
# File 'deliver/lib/deliver/loader.rb', line 72

def framed_file_paths(extensions = '{png,jpg,jpeg}')
  Dir.glob(File.join(path, "*_framed.#{extensions}"), File::FNM_CASEFOLD).sort
end

#nested?Boolean

Returns:



52
53
54
# File 'deliver/lib/deliver/loader.rb', line 52

def nested?
  @nested
end

#skip?Boolean

Returns:



64
65
66
# File 'deliver/lib/deliver/loader.rb', line 64

def skip?
  EXCEPTION_DIRECTORIES.map(&:downcase).include?(basename.downcase)
end

#valid?Boolean

Returns:



56
57
58
# File 'deliver/lib/deliver/loader.rb', line 56

def valid?
  self.class.allowed_directory_names_with_case.any? { |name| name.casecmp?(basename) }
end