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
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.
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
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
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
61 62 63 |
# File 'lib/plist4r/plist_type.rb', line 61 def to_sym return @sym ||= to_s.to_sym end |