Sha256: 258da9f94582ed4e72b7ae4752d6592cf259ec30d2813b2b2971dd51a7db754b

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

module Songkickr
  class ResultSet
    attr_accessor :page, :per_page, :total_entries, :results, :result_type, :result_key_string, :status

    def initialize(result_hash = {})
      # @result_type = "Event" or "MetroArea"
      results_page = result_hash["resultsPage"]

      if results_page
        @status        = results_page["status"]                if results_page.include? "status"
        @page          = results_page["page"]                  if results_page.include? "page"
        @per_page      = results_page["per_page"]              if results_page.include? "per_page"
        @total_entries = results_page["totalEntries"]          if results_page.include? "totalEntries"
        @results       = parse_results results_page["results"] if results_page.include? "results"
      end
    end

    protected

      def parse_results(results = {})
        return [] unless results.include? result_key_string
        results[result_key_string].inject([]) do |result_items, result_item|
          result_items << eval("Songkickr::#{result_type}.new(#{result_item})")
        end
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
songkickr-0.4.1 lib/songkickr/result_set.rb
songkickr-0.4.0 lib/songkickr/result_set.rb