Class: TextConverter
- Inherits:
-
Object
show all
- Defined in:
- lib/text_converter.rb
Defined Under Namespace
Classes: Error, NoSuchService, Service
Constant Summary
collapse
- DATABASE_URL =
'http://wedata.net/databases/Text%20Conversion%20Services/items.json'
Instance Method Summary
collapse
Instance Method Details
#convert(name, text) ⇒ Object
30
31
32
|
# File 'lib/text_converter.rb', line 30
def convert(name, text)
service(name).convert(text)
end
|
#json ⇒ Object
13
14
15
|
# File 'lib/text_converter.rb', line 13
def json
@json ||= JSON.load(open(DATABASE_URL).read)
end
|
#service(name) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/text_converter.rb', line 17
def service(name)
@services ||= json.inject({}) do |services, entry|
services[entry['name']] = Service.new(entry['name'], entry['data'])
services
end
service = @services[name]
raise NoSuchService.new(name) unless service
service
end
|