Class: Rets::Metadata::Resource
- Inherits:
-
Object
- Object
- Rets::Metadata::Resource
- Defined in:
- lib/rets/metadata/resource.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#lookup_types ⇒ Object
Returns the value of attribute lookup_types.
-
#rets_classes ⇒ Object
Returns the value of attribute rets_classes.
Class Method Summary collapse
- .build(resource_fragment, metadata) ⇒ Object
- .build_classes(resource, metadata) ⇒ Object
- .build_lookup_tree(resource, metadata) ⇒ Object
- .find_lookup_containers(metadata, resource) ⇒ Object
- .find_lookup_type_containers(metadata, resource, lookup_name) ⇒ Object
- .find_rets_classes(metadata, resource) ⇒ Object
Instance Method Summary collapse
- #find_rets_class(rets_class_name) ⇒ Object
-
#initialize(resource) ⇒ Resource
constructor
A new instance of Resource.
- #print_tree ⇒ Object
Constructor Details
#initialize(resource) ⇒ Resource
Returns a new instance of Resource.
9 10 11 12 13 14 |
# File 'lib/rets/metadata/resource.rb', line 9 def initialize(resource) self.rets_classes = [] self.lookup_types = {} self.id = resource["ResourceID"] end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/rets/metadata/resource.rb', line 7 def id @id end |
#lookup_types ⇒ Object
Returns the value of attribute lookup_types.
5 6 7 |
# File 'lib/rets/metadata/resource.rb', line 5 def lookup_types @lookup_types end |
#rets_classes ⇒ Object
Returns the value of attribute rets_classes.
4 5 6 |
# File 'lib/rets/metadata/resource.rb', line 4 def rets_classes @rets_classes end |
Class Method Details
.build(resource_fragment, metadata) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/rets/metadata/resource.rb', line 53 def self.build(resource_fragment, ) resource = new(resource_fragment) resource.lookup_types = build_lookup_tree(resource, ) resource.rets_classes = build_classes(resource, ) resource end |
.build_classes(resource, metadata) ⇒ Object
47 48 49 50 51 |
# File 'lib/rets/metadata/resource.rb', line 47 def self.build_classes(resource, ) find_rets_classes(, resource).map do |rets_class_fragment| RetsClass.build(rets_class_fragment, resource, ) end end |
.build_lookup_tree(resource, metadata) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rets/metadata/resource.rb', line 28 def self.build_lookup_tree(resource, ) lookup_types = Hash.new {|h, k| h[k] = Array.new } find_lookup_containers(, resource).each do |lookup_container| lookup_container.lookups.each do |lookup_fragment| lookup_name = lookup_fragment["LookupName"] find_lookup_type_containers(, resource, lookup_name).each do |lookup_type_container| lookup_type_container.lookup_types.each do |lookup_type_fragment| lookup_types[lookup_name] << LookupType.new(lookup_type_fragment) end end end end lookup_types end |
.find_lookup_containers(metadata, resource) ⇒ Object
16 17 18 |
# File 'lib/rets/metadata/resource.rb', line 16 def self.find_lookup_containers(, resource) [:lookup].select { |lc| lc.resource == resource.id } end |
.find_lookup_type_containers(metadata, resource, lookup_name) ⇒ Object
20 21 22 |
# File 'lib/rets/metadata/resource.rb', line 20 def self.find_lookup_type_containers(, resource, lookup_name) [:lookup_type].select { |ltc| ltc.resource == resource.id && ltc.lookup == lookup_name } end |
.find_rets_classes(metadata, resource) ⇒ Object
24 25 26 |
# File 'lib/rets/metadata/resource.rb', line 24 def self.find_rets_classes(, resource) [:class].detect { |c| c.resource == resource.id }.classes end |
Instance Method Details
#find_rets_class(rets_class_name) ⇒ Object
67 68 69 |
# File 'lib/rets/metadata/resource.rb', line 67 def find_rets_class(rets_class_name) rets_classes.detect {|rc| rc.name == rets_class_name } end |
#print_tree ⇒ Object
61 62 63 64 65 |
# File 'lib/rets/metadata/resource.rb', line 61 def print_tree puts "Resource: #{id}" rets_classes.each(&:print_tree) end |