Method: OnsOpenApi::Collection#data_for

Defined in:
lib/ons_openapi/collection.rb

#data_for(label_or_code) ⇒ Object

Returns data as array of arrays, for a geography that matches label_or_code. e.g. data_for(‘England’), data_for(‘Islington S’), data_for(‘E05002040’) Raises exception if no match or more than one match.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ons_openapi/collection.rb', line 14

def data_for label_or_code
  if geographies = geography(label_or_code)
    if geographies.size > 1
      cmds = geographies.map {|g| "data_for('#{g.title}') or data_for('#{g.item_code}') see http://statistics.data.gov.uk/doc/statistical-geography/#{g.item_code}"}
      raise "more than one match, try one of:\n\n  #{cmds.join("  \n\n  ") }\n\n"
    else
      geo = geographies.first
      data geo.item_code, geo.geography_code
    end
  end
end