Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an API that "makes sense" #3

Open
ronaldtse opened this issue Jul 18, 2024 · 0 comments
Open

Create an API that "makes sense" #3

ronaldtse opened this issue Jul 18, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@ronaldtse
Copy link
Contributor

ronaldtse commented Jul 18, 2024

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.
@ronaldtse ronaldtse added the enhancement New feature or request label Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant