class Synonymous::Response

Attributes

entries[R]
suggestions[R]

Public Class Methods

new(word, response) click to toggle source
# File lib/synonymous/response.rb, line 7
def initialize(word, response)
  data = JSON.parse(response.body)

  if data.all? { |entry| entry.is_a?(Hash) }
    entries = data.map { |result| Entry.new(result) }
    @entries, suggestions = entries.partition { |entry| entry.headword.to_s == word }
    @suggestions = suggestions.map { |entry| entry.headword.to_s }
  else
    @entries = []
    @suggestions = data
  end
end

Public Instance Methods

success?() click to toggle source
# File lib/synonymous/response.rb, line 20
def success?
  entries.any?
end