Class: Bling::API::Parser
- Inherits:
-
Object
- Object
- Bling::API::Parser
- Defined in:
- lib/bling/api/parser.rb
Instance Method Summary collapse
-
#initialize(text, klass_name) ⇒ Parser
constructor
A new instance of Parser.
- #records ⇒ Object
- #result ⇒ Object
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
#records ⇒ Object
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 |
#result ⇒ Object
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 |