Class: OldBill::V2::Neighbourhood

Inherits:
Hashie::Dash
  • Object
show all
Defined in:
lib/oldbill/v2/neighbourhood.rb

Instance Method Summary collapse

Instance Method Details

#[]=(property, value) ⇒ Object

yak!!!!! refactor me please



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/oldbill/v2/neighbourhood.rb', line 53

def []=(property, value)
  case property 
    when "locations"
    super(property.to_s, locations_parsed(value))
    when "centre"
    super(property.to_s, centre_parsed(value))
    when "contact_details"
    super(property.to_s, contact_details_parsed(value))
    when "links"
    super(property.to_s, links_parsed(value))
  else
    super
  end
end

#centre_parsed(value) ⇒ Object

Note:

This may not be exactly in the centre of the neighbourhood

latitude longitude



39
40
41
42
43
# File 'lib/oldbill/v2/neighbourhood.rb', line 39

def centre_parsed(value)
  unless value.nil?
    Hashie::Mash.new(value)
  end
end

#contact_details_parsed(value) ⇒ Object

email telephone



30
31
32
33
34
# File 'lib/oldbill/v2/neighbourhood.rb', line 30

def contact_details_parsed(value)
  unless value.nil?
    Hashie::Mash.new(value)
  end
end

#crimes_by_monthObject



74
75
76
# File 'lib/oldbill/v2/neighbourhood.rb', line 74

def crimes_by_month
  @crimes_by_month ||= session.crimes_by_month(self.force, self.neighbourhood)
end

#eventsObject



78
79
80
# File 'lib/oldbill/v2/neighbourhood.rb', line 78

def events
  @events ||= session.events(force,id)
end

#fully_loaded!Object

if not fully_loaded update its attributes



91
92
93
94
# File 'lib/oldbill/v2/neighbourhood.rb', line 91

def fully_loaded!
  return if fully_loaded
  self.send(:initialize, session.neighbourhood(force, id).to_hash) # hmm calling private method I am MAD
end

#fully_loaded?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/oldbill/v2/neighbourhood.rb', line 86

def fully_loaded?
  fully_loaded
end

url description title



22
23
24
25
26
# File 'lib/oldbill/v2/neighbourhood.rb', line 22

def links_parsed(value)
  unless value.nil?
    value.map{|link| Hashie::Mash.new(link)}
  end
end

#locations_parsed(value) ⇒ Object



45
46
47
48
49
# File 'lib/oldbill/v2/neighbourhood.rb', line 45

def locations_parsed(value)
  unless value.nil?
    value.map{|location| OldBill::V2::Neighbourhoods::Location.new(location)}
  end
end

#police_officersObject



82
83
84
# File 'lib/oldbill/v2/neighbourhood.rb', line 82

def police_officers
  @police_officers ||= session.police_officers(self.force, self.neighbourhood)
end

#street_level_crimesArray<OldBill::Crimes::StreetLevel>

Returns:

  • (Array<OldBill::Crimes::StreetLevel>)


69
70
71
72
# File 'lib/oldbill/v2/neighbourhood.rb', line 69

def street_level_crimes
  fully_loaded!
  @street_level_crimes ||= session.street_level_crimes(self.centre.latitude, self.centre.longitude)
end