Class: YoudaoFanyi::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/youdao-fanyi/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_data) ⇒ Result

Returns a new instance of Result.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/youdao-fanyi/result.rb', line 7

def initialize(xml_data)
	data = parse(xml_data)["youdao_fanyi"]
	return if data.nil?
	@error_code = data["errorCode"]
	@query = data["query"]
	@translation = data["translation"]["paragraph"] unless data["translation"].nil?
	unless data.nil?
		unless data["basic"].nil?
			unless data["basic"]["explains"].nil?
				@explains = data["basic"]["explains"]["ex"]
			end
		end
	end
	@web_explains = data["web"]["explain"] unless data["web"].nil?
end

Instance Attribute Details

#error_codeObject (readonly)

Returns the value of attribute error_code.



5
6
7
# File 'lib/youdao-fanyi/result.rb', line 5

def error_code
  @error_code
end

#explainsObject (readonly)

Returns the value of attribute explains.



5
6
7
# File 'lib/youdao-fanyi/result.rb', line 5

def explains
  @explains
end

#queryObject (readonly)

Returns the value of attribute query.



5
6
7
# File 'lib/youdao-fanyi/result.rb', line 5

def query
  @query
end

#translationObject (readonly)

Returns the value of attribute translation.



5
6
7
# File 'lib/youdao-fanyi/result.rb', line 5

def translation
  @translation
end

#web_explainsObject (readonly)

Returns the value of attribute web_explains.



5
6
7
# File 'lib/youdao-fanyi/result.rb', line 5

def web_explains
  @web_explains
end