Class: String

Inherits:
Object show all
Defined in:
lib/plist4r.rb,
lib/plist4r/mixin/ruby_stdlib.rb,
lib/plist4r/backend/ruby_cocoa.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#blobObject

The blob status of this string (set this to true if a binary string)



176
177
178
# File 'lib/plist4r/mixin/ruby_stdlib.rb', line 176

def blob
  @blob
end

Instance Method Details

#blob?true, false

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

#camelcaseObject

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

#snake_caseObject

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

#to_plistPlist4r::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

#undentObject

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  EOS\nend\n".undent


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

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