Class: Lospec::Palette::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/lospec/palette/search.rb

Constant Summary collapse

SORT_TYPES =
%i[default alphabetical downloads newest].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(colors: nil, tag: "", sort: :default) ⇒ Search

Returns a new instance of Search.



13
14
15
16
17
18
19
# File 'lib/lospec/palette/search.rb', line 13

def initialize(colors: nil, tag: "", sort: :default)
  fail ArgumentError, "Sort should be one of #{SORT_TYPES}" unless SORT_TYPES.include?(sort.to_sym)

  @colors = colors
  @tag = tag
  @sort = sort
end

Instance Attribute Details

#colorsObject (readonly)

Returns the value of attribute colors.



11
12
13
# File 'lib/lospec/palette/search.rb', line 11

def colors
  @colors
end

#sortObject (readonly)

Returns the value of attribute sort.



11
12
13
# File 'lib/lospec/palette/search.rb', line 11

def sort
  @sort
end

#tagObject (readonly)

Returns the value of attribute tag.



11
12
13
# File 'lib/lospec/palette/search.rb', line 11

def tag
  @tag
end

Instance Method Details

#resultsObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/lospec/palette/search.rb', line 21

def results(&)
  return to_enum(:results).lazy unless block_given?

  (0..).lazy.each do |page| # : Numeric
    results = results_for_page(page:)

    results.each(&)

    break if results.empty?
  end
end