Class: RETS4R::Client::Metadata

Inherits:
Hash
  • Object
show all
Defined in:
lib/rets4r/client/parsers/metadata.rb

Overview

Provides a Hash-like representation of metadata. Currently only compact metadata is supported.

String keys represent data that has come from the parsed metadata file. Symbol keys are used to indicate categories such as :lookup_types. All are pluralized except for :search_help, and have are snakecase.

The following is the basic structure of a metadata object, which generally follows the RETS specification metadata structure, but with a few notable non-nested exceptions such as lookup_types.

=> {<fkey_id> => {…},

'Comments'    => ...,
'SystemID'    => ...,
'SystemDescription' => ...
<Resource Name> => {...,
                 :lookup_types => {
                   <Lookup Name> => {<Lookup Type Value> => {...}}},

         :objects => {<Object Type> => {...}},
         :classes => {<Class Name>: => {...,
                                        :tables => {<System Name> => {...}}},
         :search_help => {<Search Help ID> => {...}},
         :lookups     => {<Lookup Name>    => {...}}
         :edit_masks: => {<Edit Mask ID>:  => {...}}

Update related metadata is currently NOT handled by the parser. The following metadata types ARE handled by the parser: System, Resource, Class, Table, Object, Lookup, LookupType, ForeignKeys, SearchHelp, and EditMask.

To generate a metadata object, use one of CompactDocument parse methods.

Defined Under Namespace

Classes: CompactDocument

Instance Method Summary collapse

Constructor Details

#initializeMetadata

The initial version of this would set the hash default_proc to create new hashes that would in turn create new hashes, which is quite clean, but also meant that you couldn't simply check to see if a given key was nil. Because this is meant to be a mostly transparent replacement of the REXML-based parser, I decided to manually create nested hashes as needed in case existing code relied on the existence of nils.


52
53
54
# File 'lib/rets4r/client/parsers/metadata.rb', line 52

def initialize
  super(Hash.new)
end

Instance Method Details

#class_tables(resource, klass) ⇒ Object


70
71
72
# File 'lib/rets4r/client/parsers/metadata.rb', line 70

def class_tables(resource, klass)
  resource_class(resource, klass)[:tables] ||= {}
end

#edit_masks(resource) ⇒ Object


91
92
93
# File 'lib/rets4r/client/parsers/metadata.rb', line 91

def edit_masks(resource)
  resource(resource)[:edit_masks] ||= {}
end

#foreign_keysObject


95
96
97
# File 'lib/rets4r/client/parsers/metadata.rb', line 95

def foreign_keys
  self[:foreign_keys] ||= {}
end

#resource(name) ⇒ Object

Helper access methods to ensure that nested hashes are created as needed.


58
59
60
# File 'lib/rets4r/client/parsers/metadata.rb', line 58

def resource(name)
  self[name] ||= {}
end

#resource_class(resource, klass) ⇒ Object


66
67
68
# File 'lib/rets4r/client/parsers/metadata.rb', line 66

def resource_class(resource, klass)
  resource_classes(resource)[klass] ||= {}
end

#resource_classes(resource) ⇒ Object


62
63
64
# File 'lib/rets4r/client/parsers/metadata.rb', line 62

def resource_classes(resource)
  resource(resource)[:classes] ||= {}
end

#resource_lookup_types(resource, lookup) ⇒ Object


82
83
84
85
# File 'lib/rets4r/client/parsers/metadata.rb', line 82

def resource_lookup_types(resource, lookup)
  lookups = resource(resource)[:lookup_types] ||= {}
  lookups[lookup] ||= {}
end

#resource_lookups(resource) ⇒ Object


78
79
80
# File 'lib/rets4r/client/parsers/metadata.rb', line 78

def resource_lookups(resource)
  resource(resource)[:lookups] ||= {}
end

#resource_objects(resource) ⇒ Object


74
75
76
# File 'lib/rets4r/client/parsers/metadata.rb', line 74

def resource_objects(resource)
  resource(resource)[:objects] ||= {}
end

#search_help(resource) ⇒ Object


87
88
89
# File 'lib/rets4r/client/parsers/metadata.rb', line 87

def search_help(resource)
  resource(resource)[:search_help] ||= {}
end