Class: HeyDan::OpenCivicIdentifiers
- Inherits:
-
Object
- Object
- HeyDan::OpenCivicIdentifiers
- Includes:
- HeyDan
- Defined in:
- lib/heydan/open_civic_identifiers.rb
Constant Summary
Constants included from HeyDan
Class Attribute Summary collapse
-
.data ⇒ Object
Returns the value of attribute data.
-
.jurisdiction_type ⇒ Object
Returns the value of attribute jurisdiction_type.
-
.jurisdictions_folder ⇒ Object
Returns the value of attribute jurisdictions_folder.
Class Method Summary collapse
Methods included from HeyDan
Class Attribute Details
.data ⇒ Object
Returns the value of attribute data.
9 10 11 |
# File 'lib/heydan/open_civic_identifiers.rb', line 9 def data @data end |
.jurisdiction_type ⇒ Object
Returns the value of attribute jurisdiction_type.
7 8 9 |
# File 'lib/heydan/open_civic_identifiers.rb', line 7 def jurisdiction_type @jurisdiction_type end |
.jurisdictions_folder ⇒ Object
Returns the value of attribute jurisdictions_folder.
8 9 10 |
# File 'lib/heydan/open_civic_identifiers.rb', line 8 def jurisdictions_folder @jurisdictions_folder end |
Class Method Details
.build(opts = {}) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/heydan/open_civic_identifiers.rb', line 15 def build(opts={}) @jurisdiction_type = HeyDan.[:type] HeyDan::Base.load_or_create_settings HeyDan::Base.create_folders @jurisdictions_folder = HeyDan.folders[:jurisdictions] download build_jurisdiction_files end |
.build_jurisdiction_files ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/heydan/open_civic_identifiers.rb', line 33 def build_jurisdiction_files if @data.nil? @data = HeyDan::Helper.get_data(name) end @progress = ProgressBar.create(:title => "Building Files in #{HeyDan.folders[:jurisdictions]} for jurisdictions #{('matching ' + @jurisdiction_type) if @jurisdiction_type}", :starting_at => 0, :total => @data[1..-1].size) if HeyDan.help? @data[1..-1].each_index do |i| row = @data[i+1] jf = HeyDan::JurisdictionFile.new(name: row[0]) next if !jf.match_type?(@jurisdiction_type) jf.add_identifier('open_civic_id', row[0].gsub('ocd-division/','')) jf.add_property('name', row[1]) jf.save @progress.progress = i if HeyDan.help? end @progress.finish if HeyDan.help? end |
.download ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/heydan/open_civic_identifiers.rb', line 24 def download if !HeyDan::Helper.dataset_exists?(name) @data = HeyDan::Helper.get_data_from_url('https://github.com/opencivicdata/ocd-division-ids/blob/master/identifiers/country-us.csv?raw=true') @data = @data[1..-1].map { |c| [c[0], c[1]]} @data.unshift(['id', 'name']) HeyDan::Helper.save_data(name, @data) end end |
.name ⇒ Object
11 12 13 |
# File 'lib/heydan/open_civic_identifiers.rb', line 11 def name 'open_civic_data' end |