Class: Plist4r::PlistType
- Includes:
- DataMethods
- Defined in:
- lib/plist4r/plist_type.rb
Defined Under Namespace
Constant Summary collapse
- ValidKeys =
{}
Constants included from DataMethods
DataMethods::ClassesForKeyType, DataMethods::ValidKeysTemplate
Class Method Summary collapse
-
.match_stat(plist_keys) ⇒ Hash
Compare a list of foreign keys to the valid keys for this known PlistType.
Instance Method Summary collapse
- #array_dict(method_sym, *args) ⇒ Object
-
#initialize(plist, *args, &blk) ⇒ PlistType
constructor
A new instance of PlistType.
-
#to_hash(hash = nil) ⇒ Plist4r::OrderedHash
Set or return the plist’s raw data object.
-
#to_s ⇒ Object
The shortform string, in snake case, a unique name.
-
#to_sym ⇒ Object
A symbol representation the shortform string, in snake case, a unique name.
Methods included from DataMethods
#_respond_to?, #method_missing, #set_or_return, #set_or_return_of_type, #validate_value
Constructor Details
#initialize(plist, *args, &blk) ⇒ PlistType
Returns 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
.match_stat(plist_keys) ⇒ Hash
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
#array_dict(method_sym, *args) ⇒ Object
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 |
#to_hash(hash = nil) ⇒ Plist4r::OrderedHash
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 |
#to_s ⇒ Object
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 |
#to_sym ⇒ Object
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 |