Sha256: 38d945e28b2818c34ca833510f56d9ad34538d888fd01e558de7b5066bbafe0d

Contents?: true

Size: 990 Bytes

Versions: 45

Compression:

Stored size: 990 Bytes

Contents

require 'nokogiri'

module Qa::Authorities
  class Tgnlang < Base
    def search(q)
      get_tgnlang(q)
    end

    def get_tgnlang(q)
      obj = []
      Tgnlang.languages.each do |h|
        obj.push(h) if h["label"].downcase.start_with?(q.downcase)
      end
      obj
    end

    def self.languages
      @languages ||=
        begin
          language_filename = File.expand_path("../../data/TGN_LANGUAGES.xml", __FILE__)
          lang_array = []
          File.open(language_filename) do |f|
            doc = Nokogiri::XML(f)
            lang_array = doc.css("Language").map do |lang|
              id = lang.css("Language_Code").first.text
              label = lang.css("Language_Name").first.text
              { "id" => id, "label" => label }
            end
          end
          lang_array
        end
    end

    def find(id)
      id = id.downcase
      Tgnlang.languages.each do |h|
        return h if h["label"].downcase == id
      end
      {}
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
qa-5.14.0 lib/qa/authorities/tgnlang.rb
qa-5.13.0 lib/qa/authorities/tgnlang.rb
qa-5.12.0 lib/qa/authorities/tgnlang.rb
qa-5.11.0 lib/qa/authorities/tgnlang.rb
qa-5.10.0 lib/qa/authorities/tgnlang.rb
qa-5.9.0 lib/qa/authorities/tgnlang.rb
qa-5.8.1 lib/qa/authorities/tgnlang.rb
qa-5.8.0 lib/qa/authorities/tgnlang.rb
qa-5.7.0 lib/qa/authorities/tgnlang.rb
qa-5.6.0 lib/qa/authorities/tgnlang.rb
qa-5.5.2 lib/qa/authorities/tgnlang.rb
qa-4.3.0 lib/qa/authorities/tgnlang.rb
qa-3.1.0 lib/qa/authorities/tgnlang.rb
qa-2.3.0 lib/qa/authorities/tgnlang.rb
qa-5.5.1 lib/qa/authorities/tgnlang.rb
qa-5.5.0 lib/qa/authorities/tgnlang.rb
qa-5.4.0 lib/qa/authorities/tgnlang.rb
qa-5.3.1 lib/qa/authorities/tgnlang.rb
qa-5.3.0 lib/qa/authorities/tgnlang.rb
qa-5.2.0 lib/qa/authorities/tgnlang.rb