class Thumbtack::Suggestion

Represents a suggestion

@api public

Constants

The key associated with popular tags

@api private

The key associated with suggested tags

@api private

Attributes

Public Class Methods

from_array(array) click to toggle source

Creates a new Suggestions from an Array of Hashes

@param [Array<Hash{String => Array<String>}>] array

Suggestions attributes

@return [Suggestion]

@api private @see Client#get

# File lib/thumbtack/suggestion.rb, line 58
def self.from_array(array)
  new(popular: entries_for(POPULAR_KEY, array),
      recommended: entries_for(RECOMMENDED_KEY, array))
end
new(attrs = EMPTY_HASH) click to toggle source

Initialize a Suggestion

@param [Hash] attrs

Suggestion attributes

@api private

# File lib/thumbtack/suggestion.rb, line 44
def initialize(attrs = EMPTY_HASH)
  @popular = attrs.fetch(:popular)
  @recommended = attrs.fetch(:recommended)
end

Private Class Methods

entries_for(key, array) click to toggle source

Extracts the entries for a given key in an array of hashes

@param [String] key

A key from which to extract the entries

@param [Array<Hash{String => Array<String>}>] array

An array of strings associated with the key

@return [Array]

@api private

# File lib/thumbtack/suggestion.rb, line 74
def self.entries_for(key, array)
  array.find { |hash| hash.key?(key) }.fetch(key, EMPTY_ARRAY)
end