Class: SupplejackApi::RecordSearchSerializer
- Inherits:
-
SearchSerializer
- Object
- ActiveModel::Serializer
- SearchSerializer
- SupplejackApi::RecordSearchSerializer
- Defined in:
- app/serializers/supplejack_api/record_search_serializer.rb
Instance Method Summary collapse
- #as_json(_options = {}) ⇒ Object
- #json_facets ⇒ Object
- #to_json(options = {}) ⇒ Object
- #to_xml(*args) ⇒ Object
- #xml_facets ⇒ Object
Instance Method Details
#as_json(_options = {}) ⇒ Object
48 49 50 51 52 |
# File 'app/serializers/supplejack_api/record_search_serializer.rb', line 48 def as_json( = {}) hash = { search: serializable_hash } hash[:search][:facets] = json_facets hash end |
#json_facets ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/serializers/supplejack_api/record_search_serializer.rb', line 18 def json_facets facets = {} object.facets.map do |facet| rows = {} facet.rows.each do |row| rows[row.value] = row.count end facets.merge!(facet.name => rows) end facets end |
#to_json(options = {}) ⇒ Object
42 43 44 45 46 |
# File 'app/serializers/supplejack_api/record_search_serializer.rb', line 42 def to_json( = {}) rendered_json = as_json().to_json rendered_json = "#{object.jsonp}(#{rendered_json})" if object.jsonp rendered_json end |
#to_xml(*args) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'app/serializers/supplejack_api/record_search_serializer.rb', line 54 def to_xml(*args) hash = serializable_hash hash[:facets] = xml_facets = {} = args.first.merge(root: :search) if args.first.is_a?(Hash) hash.to_xml() end |
#xml_facets ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'app/serializers/supplejack_api/record_search_serializer.rb', line 31 def xml_facets facets = [] object.facets.map do |facet| values = facet.rows.map do |row| { name: row.value, count: row.count } end facets << { name: facet.name.to_s, values: values } end facets end |