Module: Iev::DataSource

Defined in:
lib/iev/data_source.rb

Defined Under Namespace

Classes: NotFoundError

Class Method Summary collapse

Class Method Details

.fetch_concept(code) ⇒ Hash?

Fetch full concept data (all languages) for a given IEV code.

Parameters:

  • code (String)

    IEV code, e.g. “103-01-02”

Returns:

  • (Hash, nil)

    concept data hash or nil if not found



16
17
18
# File 'lib/iev/data_source.rb', line 16

def fetch_concept(code)
  fetch_concept_data(code)
end

.fetch_term(code, lang) ⇒ Hash?

Fetch localized term data for a given IEV code and language.

Parameters:

  • code (String)

    IEV code, e.g. “103-01-02”

  • lang (String)

    language code, e.g. “en” or “eng”

Returns:

  • (Hash, nil)

    localized concept data or nil



25
26
27
28
29
30
31
# File 'lib/iev/data_source.rb', line 25

def fetch_term(code, lang)
  concept = fetch_concept(code)
  return nil unless concept

  lang_key = normalize_lang(lang)
  concept[lang_key]
end

.fetch_term_designation(code, lang) ⇒ String?

Fetch the term designation string for a given IEV code and language. This is the backward-compatible replacement for the scraping-based Iev.get.

Parameters:

  • code (String)

    IEV code, e.g. “103-01-02”

  • lang (String)

    language code, e.g. “en”

Returns:

  • (String, nil)

    term designation or nil



39
40
41
42
43
44
45
46
47
48
# File 'lib/iev/data_source.rb', line 39

def fetch_term_designation(code, lang)
  term_data = fetch_term(code, lang)
  return nil unless term_data

  terms = term_data["terms"]
  return nil unless terms&.any?

  preferred = terms.find { |t| t["normative_status"] == "preferred" }
  (preferred || terms.first)["designation"]
end