-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
enhancementNew feature or requestNew feature or request
Description
The current Ruby classes directly model the Genericode XML structure, which makes very little sense.
This task is to create/refactor a set of classes so that people can actually easily create code lists and serialize into / deserialize from the Genericode formats.
e.g.
Taking the example from the OASIS standard, "B.1. UBL Example – Country Codes":
metadata = Identifier.new(
short: "CountryIdentificationCode",
long: "Country",
version: "0.3",
canonical_uri: "urn:oasis:names:specification:ubl:codelist:gc:CountryIdentificationCode",
canonical_version_uri: "urn:oasis:names:specification:ubl:codelist:gc:CountryIdentificationCode-2.0",
location_uri: "http://docs.oasis-open.org/ubl/os-ubl-2.0/cl/gc/default/CountryIdentificationCode-2.0.gc"
agency: Agency.new(
long: LocalizedString.new("United Nations Economic Commission for Europe", :eng),
id: 6
)
)
column_set = ColumnSet.new(
columns: [
Column.new(id: "code", data_type: String, use: :required),
Column.new(id: "name", data_type: String, use: :optional),
Column.new(id: "numericode", data_type: String, use: :optional)
],
keys: [
Key.new(id: "codeKey", short: "CodeKey", column_ref: "code")
]
)
rows = [
Row.new(values: { "code" => "AF", "name" => "AFGHANISTAN", "numericode" => "004" }),
Row.new(values: { "code" => "AL", "name" => "ALBANIA", "numericode" => "008" }),
# ...
Row.new(values: { "code" => "ZM", "name" => "ZAMBIA", "numericode" => "894" }),
Row.new(values: { "code" => "ZW", "name" => "ZIMBABWE", "numericode" => "716" }),
]
cl = CodeList.new(
identification: metadata,
column_set: column_set,
rows: rows
)Then:
af = cl.lookup(key: "code", value: "AF")
=> #<Row ... "code" => "AF", "name" => "AFGHANISTAN", "numericode" => "004">
af.name
=> "AFGHANISTAN"
af.numericode
=> "004"
zm = cl.lookup(key: "name", value: "ZAMBIA")
zm.code
=> "ZM"
zm.numericode
=> "716"
# etc.Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request