Class: String

Defined in:
lib/plist4r.rb,
lib/plist4r/mixin/ruby_stdlib.rb,
lib/plist4r/backend/ruby_cocoa.rb

Instance Methods

Instance Attributes

Instance Method Details

- (true, false) blob?

Returns whether or not str is a blob.

Returns:

  • (true, false)

    If true, this string contains binary data. If false, its a regular string



180
181
182
# File 'lib/plist4r/mixin/ruby_stdlib.rb', line 180

def blob?
  @blob
end

- (Object) camelcase

A Camel-ized string. The reverse of #snake_case

Examples:

"my_plist_key".camelcase => "MyPlistKey"


201
202
203
204
# File 'lib/plist4r/mixin/ruby_stdlib.rb', line 201

def camelcase
  str = self.dup.gsub(/(^|[-_.\s])([a-zA-Z0-9])/) { $2.upcase } \
                .gsub('+', 'x')
end

- (Object) snake_case

A snake-cased string. The reverse of #camelcase

Examples:

"MyPlistKey".snake_case => "my_plist_key"


209
210
211
212
# File 'lib/plist4r/mixin/ruby_stdlib.rb', line 209

def snake_case
  str = self.dup.gsub(/[A-Z]/) {|s| "_" + s}
  str = str.downcase.sub(/^\_/, "")
end

- (Plist4r::Plist) to_plist

Converts a string of plist data into a new Plist4r::Plist object

Returns:

See Also:



90
91
92
# File 'lib/plist4r.rb', line 90

def to_plist
  return ::Plist4r.new(:from_string => self)
end

- (Object) undent

Remove the leading spaces of the first line, and same to all lines of a multiline string. This effectively shifts all the lines across to the left, until the first line hits the left margin.

Examples:

def usage; "# leading indent\n# subsequent indent\n# subsequent indent + '  '\n".undent
end


194
195
196
# File 'lib/plist4r/mixin/ruby_stdlib.rb', line 194

def undent
  gsub /^.{#{slice(/^ +/).length}}/, ''
end