Class: Qa::Authorities::Tgnlang

Inherits:
Object
  • Object
show all
Extended by:
Deprecation
Defined in:
lib/qa/authorities/tgnlang.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTgnlang

Returns a new instance of Tgnlang.



8
9
# File 'lib/qa/authorities/tgnlang.rb', line 8

def initialize
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

Class Method Details

.languagesObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/qa/authorities/tgnlang.rb', line 25

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

#full_record(id, sub_authority) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/qa/authorities/tgnlang.rb', line 51

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

#get_full_record(id, sub_authority) ⇒ Object



46
47
48
49
# File 'lib/qa/authorities/tgnlang.rb', line 46

def get_full_record(id, sub_authority)
  Deprecation.warn(Tgnlang, "get_full_record is deprecated and will be removed in 0.1.0. Use full_record instead", caller)
  full_record(id, sub_authority)
end

#getTgnLang(q) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/qa/authorities/tgnlang.rb', line 15

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

#resultsObject



42
43
44
# File 'lib/qa/authorities/tgnlang.rb', line 42

def results
  self.response
end

#search(q, sub_authority = '') ⇒ Object



11
12
13
# File 'lib/qa/authorities/tgnlang.rb', line 11

def search(q, sub_authority='')
  self.response = getTgnLang(q)
end