Class: GS::Text

Inherits:
Object
  • Object
show all
Defined in:
lib/goldshark_gem/text.rb

Instance Method Summary collapse

Constructor Details

#initialize(localization = nil) ⇒ Text

Returns a new instance of Text.



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/goldshark_gem/text.rb', line 3

def initialize(localization = nil)
	unless localization.nil?
		config_file = Rails.root.join("config", "tool_config.yml").to_s
		tool_info = YAML::load(File.read(config_file))
		@tool_guid = tool_info[localization]['tool_guid']
		@locale = tool_info[localization]['locale']
	end
	@url = tool_info['api_root'] rescue nil
	if @url.nil?
		@url = 'http://gst.api.igodigital.com/v2_2'
	end
end

Instance Method Details

#find(param) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/goldshark_gem/text.rb', line 57

def find(param)
	@texts.each do |x|
		type = x[:text_type]
		if type == param || type == param.parameterize.underscore || type == param.downcase.underscore
			return x[:text_value]
		end
	end
	return nil
end

#load_textObject



48
49
50
51
52
53
54
55
# File 'lib/goldshark_gem/text.rb', line 48

def load_text
	uri = URI.parse("#{@url}/#{@tool_guid}/text.json?locale=#{@locale}")
	http = Net::HTTP.new(uri.host, uri.port)
	request = Net::HTTP::Get.new(uri.request_uri)
	response = http.request(request)
	@texts = JSON.parse(response.body, {symbolize_names: true})
	return @texts
end

#locale(locale = nil) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/goldshark_gem/text.rb', line 16

def locale(locale = nil)
	if locale.nil?
		@locale
	else
		@locale = locale
	end
end

#texts(texts = []) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/goldshark_gem/text.rb', line 40

def texts(texts = [])
	if texts.empty?
		@texts
	else
		@texts = texts
	end
end

#tool_guid(tool_guid = nil) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/goldshark_gem/text.rb', line 24

def tool_guid(tool_guid = nil)
	if tool_guid.nil?
		@tool_guid
	else
		@tool_guid = tool_guid
	end
end

#url(url = nil) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/goldshark_gem/text.rb', line 32

def url(url = nil)
	if url.nil?
		@url
	else
		@url = url
	end
end