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] ||= camelize(name, :uppercase_first_letter => false)
    else
      cache = plist_cache[:normal] ||= {}
      cache[name] ||= camelize(name)
    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.


74
75
76
# File 'lib/xcodeproj/project/case_converter.rb', line 74

def self.convert_to_ruby(name)
  underscore(name.to_s).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.


84
85
86
# File 'lib/xcodeproj/project/case_converter.rb', line 84

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