Class: Yahoo::Placemaker::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/yahoo/placemaker/document.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Document) initialize(json)

A new instance of Document



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/yahoo/placemaker/document.rb', line 12

def initialize(json)

  if json['geographicScope']
    @geographic_scope = Yahoo::Placemaker::GeographicScope.new(json['geographicScope'])
  end

  # If Yahoo has detected a continent then it will return some REALLY annoying data. It will
  # give us back administrativeScope hash w/ a type of "Undefined" and coordinates of 0,0.
  # Obviously this isn't useful information so we won't set @administrative_scope in that case

  if json['administrativeScope']
    unless json['administrativeScope']['type'] == 'Undefined'
      @administrative_scope = Yahoo::Placemaker::AdministrativeScope.new(json['administrativeScope'])
    end
  end

  @places = Array.new

  # if the placeDetails key exists then that means that we
  # only have one result so we'll just use it. Otherwise
  # yahoo has given us back some POORLY formatted data which
  # is in numeric keys so we'll search for them and pull them out

  if json['placeDetails']
      @places << Yahoo::Placemaker::Place.new(json['placeDetails'])
  end

  if json.class == Hash
    multiple_place_details = (json.map{ |k,v| k =~ /^[\d]+$/ ? v : nil }).compact
    if multiple_place_details.any?
      multiple_place_details.each do |place|
          @places << Yahoo::Placemaker::Place.new(place['placeDetails'])
      end
    end
  end

  @local_scopes = Array.new
  if json['localScopes']
    if json['localScopes'].class == Array
      json['localScopes'].each do |ls|
        @local_scopes << Yahoo::Placemaker::LocalScope.new(ls['localScope'])
      end
    else
        @local_scopes << Yahoo::Placemaker::LocalScope.new(json['localScopes']['localScope'])
    end
  end

  if json['extents']
    @extents = Yahoo::Placemaker::Extents.new(json['extents'])
  end

  # referenceList -> references

  @references = Array.new
  if json['referenceList']
    if json['referenceList'].class == Array
      json['referenceList'].each do |reference|
        @references << Yahoo::Placemaker::Reference.new(reference)
      end
    else
      @references << Yahoo::Placemaker::Reference.new(json['referenceList']['reference'])
    end
  end

end

Instance Attribute Details

- (Object) administrative_scope

Returns the value of attribute administrative_scope



11
12
13
# File 'lib/yahoo/placemaker/document.rb', line 11

def administrative_scope
  @administrative_scope
end

- (Object) extents

Returns the value of attribute extents



11
12
13
# File 'lib/yahoo/placemaker/document.rb', line 11

def extents
  @extents
end

- (Object) geographic_scope

Returns the value of attribute geographic_scope



11
12
13
# File 'lib/yahoo/placemaker/document.rb', line 11

def geographic_scope
  @geographic_scope
end

- (Object) local_scopes

Returns the value of attribute local_scopes



11
12
13
# File 'lib/yahoo/placemaker/document.rb', line 11

def local_scopes
  @local_scopes
end

- (Object) places

Returns the value of attribute places



11
12
13
# File 'lib/yahoo/placemaker/document.rb', line 11

def places
  @places
end

- (Object) references

Returns the value of attribute references



11
12
13
# File 'lib/yahoo/placemaker/document.rb', line 11

def references
  @references
end