Module: Xcodeproj::Project::Object::CaseConverter

Defined in:
lib/xcodeproj/project/case_converter.rb

Overview

Converts between camel case names used in the xcodeproj plist files and the ruby symbols used to represent them.

Class Method Summary collapse

Class Method Details

.convert_to_plist(name, type = nil) ⇒ String

Returns The plist equivalent of the given Ruby name.

Examples:

CaseConverter.convert_to_plist(:project_ref) #=> ProjectRef

Parameters:

  • name (Symbol, String)

    The name to convert

  • type (Symbol, Nil) (defaults to: nil)

    The type of conversion. Pass ‘nil` for normal camel case and `:lower` for camel case starting with a lower case letter.

Returns:

  • (String)

    The plist equivalent of the given Ruby name.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/xcodeproj/project/case_converter.rb', line 20

def self.convert_to_plist(name, type = nil)
  case name
  when :remote_global_id_string
    'remoteGlobalIDString'
  else
    if type == :lower
      cache = plist_cache[:lower] ||= {}
      cache[name] ||= name.to_s.camelize(:lower)
    else
      cache = plist_cache[:normal] ||= {}
      cache[name] ||= name.to_s.camelize
    end
  end
end

.convert_to_ruby(name) ⇒ Symbol

Returns The Ruby equivalent of the given plist name.

Examples:

CaseConverter.convert_to_ruby('ProjectRef') #=> :project_ref

Parameters:

  • name (String)

    The name to convert

Returns:

  • (Symbol)

    The Ruby equivalent of the given plist name.



43
44
45
# File 'lib/xcodeproj/project/case_converter.rb', line 43

def self.convert_to_ruby(name)
  name.to_s.underscore.to_sym
end

.plist_cacheHash

Note:

A cache is used because this operation is performed for each attribute of the project when it is saved and caching it has an important performance benefit.

Returns A cache for the conversion to the Plist format.

Returns:

  • (Hash)

    A cache for the conversion to the Plist format.



53
54
55
# File 'lib/xcodeproj/project/case_converter.rb', line 53

def self.plist_cache
  @plist_cache ||= {}
end