class GoogleWebTranslate::Result
Translation results
Constants
- DATA_INDICES
@private
Attributes
raw[R]
Public Class Methods
new(data)
click to toggle source
# File lib/google_web_translate/result.rb, line 19 def initialize(data) @raw = data @keys = [] @properties = {} DATA_INDICES.each do |key, indices| indices = indices.dup extract_data(key, *indices) end @alternatives = @alternatives.collect { |i| i[0] } if @alternatives @keys.each { |key| @properties[key] = instance_variable_get("@#{key}") } end
Public Instance Methods
to_h()
click to toggle source
# File lib/google_web_translate/result.rb, line 33 def to_h @properties end
Private Instance Methods
array_value(array, *indices)
click to toggle source
# File lib/google_web_translate/result.rb, line 46 def array_value(array, *indices) return nil if array.nil? index = indices.shift value = array[index] return value if indices.empty? array_value(value, *indices) end
extract_data(name, *indices)
click to toggle source
# File lib/google_web_translate/result.rb, line 39 def extract_data(name, *indices) value = array_value(@raw, *indices) return if value.nil? instance_variable_set("@#{name}", value) @keys.push(name) end