Class: Qa::Authorities::Tgnlang

Inherits:
Base
  • Object
show all
Defined in:
lib/qa/authorities/tgnlang.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#all

Class Method Details

.languagesObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/qa/authorities/tgnlang.rb', line 17

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

Instance Method Details

#find(id) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/qa/authorities/tgnlang.rb', line 34

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

#get_tgnlang(q) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/qa/authorities/tgnlang.rb', line 9

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

#search(q) ⇒ Object



5
6
7
# File 'lib/qa/authorities/tgnlang.rb', line 5

def search(q)
  get_tgnlang(q)
end