Class: Deliver::Loader::LanguageFolder
- Inherits:
-
Object
- Object
- Deliver::Loader::LanguageFolder
- Defined in:
- deliver/lib/deliver/loader.rb
Overview
A class that represents language folder under screenshots or metadata folder
Instance Attribute Summary collapse
-
#language ⇒ String
readonly
A normalized language name that corresponds to the directory’s name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #basename ⇒ Object
- #expandable? ⇒ Boolean
- #file_paths(extensions = '{png,jpg,jpeg}') ⇒ Object
- #framed_file_paths(extensions = '{png,jpg,jpeg}') ⇒ Object
-
#initialize(path, nested: false) ⇒ LanguageFolder
constructor
A new instance of LanguageFolder.
- #nested? ⇒ Boolean
- #skip? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(path, nested: false) ⇒ LanguageFolder
Returns a new instance of LanguageFolder.
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
#language ⇒ String (readonly)
Returns 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 |
#path ⇒ Object (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_case ⇒ Object
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_languages ⇒ Object
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 available) Deliver::Languages::ALL_LANGUAGES end |
Instance Method Details
#basename ⇒ Object
76 77 78 |
# File 'deliver/lib/deliver/loader.rb', line 76 def basename File.basename(@path) end |
#expandable? ⇒ Boolean
60 61 62 |
# File 'deliver/lib/deliver/loader.rb', line 60 def !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 |
#skip? ⇒ Boolean
64 65 66 |
# File 'deliver/lib/deliver/loader.rb', line 64 def skip? EXCEPTION_DIRECTORIES.map(&:downcase).include?(basename.downcase) end |
#valid? ⇒ Boolean
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 |