Sha256: 97fe9f7cc20fc2c62bdbccf5ebaa3b9ad387f95f44f6417af52e60564d9ca1e0
Contents?: true
Size: 707 Bytes
Versions: 16
Compression:
Stored size: 707 Bytes
Contents
require 'net/http' require 'net/https' # for ruby 1.8.7 require 'json' module BRPopulate def self.states http = Net::HTTP.new('raw.github.com', 443); http.use_ssl = true JSON.parse http.get('/celsodantas/br_populate/master/states.json').body end def self.capital?(city, state) city["name"] == state["capital"] end def self.populate states.each do |state| state_obj = State.new(:acronym => state["acronym"], :name => state["name"]) state_obj.save state["cities"].each do |city| c = City.new c.name = city c.state = state_obj c.capital = capital?(city, state) c.save end end end end BRPopulate.populate
Version data entries
16 entries across 16 versions & 2 rubygems