class DictionaryAPI::DictionaryAPI::Parser
Public Instance Methods
parse(response)
click to toggle source
# File lib/dictionary_api/parser.rb, line 8 def parse(response) response['def'].inject([]) { |result, response_el| result << self.build_article(response_el) } end
Protected Instance Methods
build_array(articles_array)
click to toggle source
# File lib/dictionary_api/parser.rb, line 34 def build_array(articles_array) articles_array.inject([]) do |result, element| result << element.to_a.inject([]) do |result, el| result << (el[1].class == Array ? self.build_array(el[1]) : el[1]) end result.flatten! end end
build_article(articles_hash)
click to toggle source
# File lib/dictionary_api/parser.rb, line 14 def build_article(articles_hash) article = Article.new article.text = articles_hash['text'] article.position = articles_hash['pos'] article.transcription = articles_hash['ts'] article.translation = articles_hash['tr'].inject([]) { |result, el| result << self.build_translation_article(el) } article end
build_translation_article(articles_hash)
click to toggle source
# File lib/dictionary_api/parser.rb, line 23 def build_translation_article(articles_hash) translation_article = TranslationArticle.new translation_article.text = articles_hash['text'] translation_article.position = articles_hash['pos'] translation_article.synonym = self.build_array(articles_hash['syn']) unless articles_hash['syn'].nil? translation_article.meaning = self.build_array(articles_hash['mean']) unless articles_hash['mean'].nil? translation_article.example = self.build_array(articles_hash['ex']) unless articles_hash['ex'].nil? translation_article.aspect = articles_hash['asp'] translation_article end