Class: Plist4r::ArrayDict

Includes:
DataMethods
Defined in:
lib/plist4r/mixin/array_dict.rb

Direct Known Subclasses

Instance Methods

Methods included from DataMethods

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

Overview

Abstract Base class. Represents some nested data structure within an open Plist. Typically, a PlistType will create and build upon nested instances of this class.

Constant Summary

Constants included from DataMethods

ClassesForKeyType, ValidKeys, ValidKeysTemplate

Constructor Details

- (ArrayDict) initialize(orig, index = nil, &blk)

The initializer for this object. Here we set a reference to our raw data structure, which typically is a nested hash within the plist root hash object. Or an Array type structure if index is set.

Parameters:

  • (OrderedHash) orig

    The nested hash object which this structure represents.

  • (Fixnum) index (defaults to: nil)

    The Array index (if representing an Array structure)



15
16
17
18
19
20
21
22
# File 'lib/plist4r/mixin/array_dict.rb', line 15

def initialize orig, index=nil, &blk
  @orig = orig
  @orig = @orig[index] if index
  @hash = ::Plist4r::OrderedHash.new

  @block = blk
  instance_eval(&@block) if block_given?
end

Dynamic Method Handling

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

Instance Method Details

- (Plist4r::OrderedHash) hash

The raw data object

Returns:



26
27
28
# File 'lib/plist4r/mixin/array_dict.rb', line 26

def hash
  @hash
end

- (Object) select(*keys)

Select (keep) plist keys from the object. Copy them to the resultant object moving forward.

Parameters:

  • (Array, *args) keys

    The list of Plist Keys to keep



37
38
39
40
41
42
# File 'lib/plist4r/mixin/array_dict.rb', line 37

def select *keys
  keys.flatten.each do |k|
    k = k.to_s.camelcase if k.class == Symbol
    @hash[k] = @orig[k] if @orig[k]
  end
end

- (Object) select_all

Select (keep) all plist keys from the object. Copy them to the resultant object moving forward.



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

def select_all
  @hash = @orig
end

- (Object) to_hash



30
31
32
# File 'lib/plist4r/mixin/array_dict.rb', line 30

def to_hash
  @hash
end

- (Object) unselect(*keys)

Unselect (delete) plist keys from the object.

Parameters:

  • (Array, *args) keys

    The list of Plist Keys to delete



46
47
48
49
50
51
52
# File 'lib/plist4r/mixin/array_dict.rb', line 46

def unselect *keys
  @hash = @orig
  keys.flatten.each do |k|
    k = k.to_s.camelcase if k.class == Symbol
    @hash.delete k
  end
end

- (Object) unselect_all

Unselect (delete) all plist keys from the object.



55
56
57
# File 'lib/plist4r/mixin/array_dict.rb', line 55

def unselect_all
  @hash = Plist4r::OrderedHash.new
end