Skip to content

Commit

Permalink
fix: Fix parse error when data is missing (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilkie authored May 13, 2024
1 parent 9602657 commit e3aab0b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/pumi/data_source/ncdd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module Pumi
module DataSource
class NCDD
CSV_HEADERS = %w[type code name_km name_latin reference note1 note2].freeze
MISSING_DATA = {
"1715" => { type: "ក្រុង" }
}.freeze

AdministrativeUnit = Struct.new(:en, :km, :latin, :code_length, :group, :type, keyword_init: true)
Row = Struct.new(:code, :name_km, :name_latin, :type, keyword_init: true) do
Expand Down Expand Up @@ -61,11 +64,13 @@ def parse_source_file(file)
end

def build_row(row)
code = parse_location_code(row)

Row.new(
code: parse_location_code(row),
code:,
name_km: row.fetch("name_km"),
name_latin: row.fetch("name_latin"),
type: row.fetch("type")
type: row.fetch("type") || MISSING_DATA.dig(code, :type)
)
end

Expand Down

0 comments on commit e3aab0b

Please sign in to comment.