Class: Bling::API::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/bling/api/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(text, klass_name) ⇒ Parser

Returns a new instance of Parser.



7
8
9
# File 'lib/bling/api/parser.rb', line 7

def initialize(text, klass_name)
  @text, @klass_name = text, klass_name
end

Instance Method Details

#recordsObject



16
17
18
19
20
# File 'lib/bling/api/parser.rb', line 16

def records
  raw_records = result[:return][plural_klass_name]
  return [] if raw_records.nil?
  raw_records.each_with_object([]) { |record, result| result << Record.new(record[@klass_name]) }
end

#resultObject



11
12
13
14
# File 'lib/bling/api/parser.rb', line 11

def result
  raw_response = JSON.parse(@text)
  Translator.translate_hash(raw_response, to: :en)
end