Class: OpenStax::Api::V1::AbstractSearchRepresenter

Inherits:
Roar::Decorator
  • Object
show all
Includes:
Roar::JSON
Defined in:
app/representers/openstax/api/v1/abstract_search_representer.rb

Instance Method Summary collapse

Instance Method Details

#itemsObject



34
35
36
37
38
39
# File 'app/representers/openstax/api/v1/abstract_search_representer.rb', line 34

def items
  return represented.items.to_a.uniq if represented.respond_to?(:items)
  return represented[:items].to_a.uniq if represented.respond_to?(:has_key?) && \
                                          represented.has_key?(:items)
  represented.to_a.uniq
end

#total_countObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/representers/openstax/api/v1/abstract_search_representer.rb', line 41

def total_count
  return represented.total_count if represented.respond_to?(:total_count)
  return represented[:total_count] if represented.respond_to?(:has_key?) && \
                                      represented.has_key?(:total_count)

  @items = items
  if @items.respond_to?(:length)
    if @items.respond_to?(:limit) && @items.respond_to?(:offset)
      @items.limit(nil).offset(nil).length
    else
      @items.length
    end
  else
    1
  end
end