Class: TranslatorAPI::Parser
- Inherits:
-
Object
- Object
- TranslatorAPI::Parser
- Defined in:
- lib/translator_api/parser.rb
Instance Method Summary collapse
-
#initialize(json) ⇒ Parser
constructor
A new instance of Parser.
- #parse(method_get_list = false) ⇒ Object
Constructor Details
#initialize(json) ⇒ Parser
Returns a new instance of Parser.
8 9 10 |
# File 'lib/translator_api/parser.rb', line 8 def initialize(json) @json = JSON.parse json end |
Instance Method Details
#parse(method_get_list = false) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/translator_api/parser.rb', line 12 def parse(method_get_list = false) fail Error::YandexError.new, @json['message'] if @json['code'] && method_get_list fail Error::YandexError.new, @json['message'] if @json['code'] != Error::YandexError::CODES[:ok] && !method_get_list rescue => ex return Error::YandexError.new.handling_error(ex) else if @json['dirs'] return @json['langs'], @json['dirs'] elsif @json['text'] return @json['text'].join else return @json['lang'] end end |