Class: Plist4r::PlistType

Includes:
DataMethods
Defined in:
lib/plist4r/plist_type.rb

Direct Known Subclasses

Classes

Class Methods

Instance Methods

Methods included from DataMethods

#_respond_to?, #method_missing, #set_or_return, #set_or_return_of_type, #validate_value

Constant Summary

ValidKeys =
{}

Constants included from DataMethods

ClassesForKeyType, ValidKeys, ValidKeysTemplate

Constructor Details

- (PlistType) initialize(plist, *args, &blk)

A new instance of PlistType

Parameters:

  • (Plist4r::Plist) plist

    A pointer referencing back to the plist object



12
13
14
15
# File 'lib/plist4r/plist_type.rb', line 12

def initialize plist, *args, &blk
  @plist = plist
  @hash = @orig = plist.to_hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Plist4r::DataMethods

Class Method Details

+ (Hash) match_stat(plist_keys)

Compare a list of foreign keys to the valid keys for this known PlistType. Generate statistics about how many keys (what proportion) match the the key names match this particular PlistType.

Examples:

Plist4r::PlistType::Launchd.match_stat ["ProgramArguments","Sockets","SomeArbitraryKeyName"]
# => { :matches => 2, :ratio => 0.0465116279069767 }

Parameters:

  • (Array) plist_keys

    The list of keys to compare to this PlistType

Returns:

  • (Hash)

    A hash of the match statistics

See Also:



40
41
42
43
44
45
# File 'lib/plist4r/plist_type.rb', line 40

def self.match_stat plist_keys
  type_keys = self::ValidKeys.values.flatten
  matches = plist_keys & type_keys
  include_ratio = matches.size.to_f / type_keys.size
  return :matches => matches.size, :ratio => include_ratio
end

Instance Method Details

- (Object) array_dict(method_sym, *args)



65
66
67
68
69
70
# File 'lib/plist4r/plist_type.rb', line 65

def array_dict method_sym, *args
  a = ArrayDict.new @hash
  result = eval "a.#{method_sym} *args"
  @hash = @orig = a.to_hash
  @plist.import_hash a.to_hash
end

- (Plist4r::OrderedHash) to_hash(hash = nil)

Set or return the plist’s raw data object

Parameters:

Returns:



20
21
22
23
24
25
26
27
28
29
# File 'lib/plist4r/plist_type.rb', line 20

def to_hash hash=nil
  case hash
  when ::Plist4r::OrderedHash
    @hash = @orig = hash
  when nil
    @hash
  else
    raise "Must hash be an ::Plist4r::OrderedHash"
  end
end

- (Object) to_s

The shortform string, in snake case, a unique name

Examples:

pt = Plist4r::PlistType::Launchd.new
pt.to_s
# => "launchd"

Returns:

  • The shortform string, in snake case, a unique name



52
53
54
# File 'lib/plist4r/plist_type.rb', line 52

def to_s
  return @string ||= self.class.to_s.gsub(/.*:/,"").snake_case
end

- (Object) to_sym

A symbol representation the shortform string, in snake case, a unique name

Examples:

pt = Plist4r::PlistType::Launchd.new
pt.to_sym
# => :launchd

Returns:

  • A symbol representation the shortform string, in snake case, a unique name



61
62
63
# File 'lib/plist4r/plist_type.rb', line 61

def to_sym
  return @sym ||= to_s.to_sym
end