Class: Qa::Authorities::Tgnlang

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(q, sub_authority = '') ⇒ Tgnlang

Returns a new instance of Tgnlang.



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

def initialize(q,sub_authority='')
  self.raw_response = getTgnLang(q)
end

Instance Attribute Details

#raw_responseObject

Returns the value of attribute raw_response.



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

def raw_response
  @raw_response
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#getTgnLang(q) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/qa/authorities/tgnlang.rb', line 11

def getTgnLang(q)
  str = File.expand_path("../../data/TGN_LANGUAGES.xml", __FILE__)
  doc = Nokogiri::XML(File.open(str))
  size = doc.css("Language_Name").size
  i=0
  lang_array = Array.new
  while i < size do
    lang_hash = Hash.new
    lang_hash["id"] = doc.css("Language_Code")[i].text
    lang_hash["label"] = doc.css("Language_Name")[i].text
    lang_array.push(lang_hash)
    i+=1
  end
  obj = Array.new      
  lang_array.each do |h|
    if h["label"].downcase.start_with?(q.downcase)  
      obj.push(h)
    end
  end
  obj.to_json
end

#parse_authority_responseObject



36
37
38
# File 'lib/qa/authorities/tgnlang.rb', line 36

def parse_authority_response
  self.raw_response
end

#resultsObject



33
34
35
# File 'lib/qa/authorities/tgnlang.rb', line 33

def results
  self.raw_response
end