Class: AdLocalize::Requests::ExportRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/ad_localize/requests/export_request.rb

Constant Summary collapse

SUPPORTED_PLATFORMS =
%w(ios android yml json properties csv).freeze
DEFAULT_EXPORT_FOLDER =
'exports'.freeze
CSV_CONTENT_TYPES =
%w(text/csv text/plain application/csv).freeze
EMPTY_CONTENT_TYPE =
'inode/x-empty'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ ExportRequest

Returns a new instance of ExportRequest.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ad_localize/requests/export_request.rb', line 9

def initialize(**args)
  @locales = Array(args[:locales].presence)
  @platforms = args[:platforms].blank? ? SUPPORTED_PLATFORMS : Array(args[:platforms])
  @csv_paths = Array(args[:csv_paths])
  @g_spreadsheet_options = args[:g_spreadsheet_options]
  @verbose = args[:verbose].presence || false
  @output_path = Pathname.new(args[:output_path].presence || DEFAULT_EXPORT_FOLDER)
  if @csv_paths.size > 1 || @g_spreadsheet_options&.has_multiple_sheets?
    @merge_policy = MergePolicy.new(policy: args[:merge_policy].presence || MergePolicy::DEFAULT_POLICY)
  else
    @merge_policy = nil
  end
end

Instance Attribute Details

#csv_pathsObject

Returns the value of attribute csv_paths.



32
33
34
# File 'lib/ad_localize/requests/export_request.rb', line 32

def csv_paths
  @csv_paths
end

#g_spreadsheet_optionsObject (readonly)

Returns the value of attribute g_spreadsheet_options.



23
24
25
# File 'lib/ad_localize/requests/export_request.rb', line 23

def g_spreadsheet_options
  @g_spreadsheet_options
end

#localesObject (readonly)

Returns the value of attribute locales.



23
24
25
# File 'lib/ad_localize/requests/export_request.rb', line 23

def locales
  @locales
end

#merge_policyObject (readonly)

Returns the value of attribute merge_policy.



23
24
25
# File 'lib/ad_localize/requests/export_request.rb', line 23

def merge_policy
  @merge_policy
end

#output_pathObject (readonly)

Returns the value of attribute output_path.



23
24
25
# File 'lib/ad_localize/requests/export_request.rb', line 23

def output_path
  @output_path
end

#platformsObject (readonly)

Returns the value of attribute platforms.



23
24
25
# File 'lib/ad_localize/requests/export_request.rb', line 23

def platforms
  @platforms
end

#verboseObject (readonly)

Returns the value of attribute verbose.



23
24
25
# File 'lib/ad_localize/requests/export_request.rb', line 23

def verbose
  @verbose
end

Instance Method Details

#has_csv_files?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/ad_localize/requests/export_request.rb', line 34

def has_csv_files?
  !@csv_paths.blank? && @csv_paths.all? { |csv_path| File.exist?(csv_path) && is_csv?(path: csv_path) }
end

#has_empty_files?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/ad_localize/requests/export_request.rb', line 38

def has_empty_files?
  !@csv_paths.blank? && @csv_paths.all? { |csv_path| File.exist?(csv_path) && is_empty?(path: csv_path) }
end

#has_g_spreadsheet_options?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/ad_localize/requests/export_request.rb', line 42

def has_g_spreadsheet_options?
  @g_spreadsheet_options.present?
end

#multiple_platforms?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/ad_localize/requests/export_request.rb', line 46

def multiple_platforms?
  @platforms.size > 1
end

#valid?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/ad_localize/requests/export_request.rb', line 50

def valid?
  valid_platforms? && (valid_csv_options? || valid_g_spreadsheet_options?)
end

#verbose?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/ad_localize/requests/export_request.rb', line 54

def verbose?
  verbose
end