Sha256: c6c97f1c088cf3ba784940e72e124859b52c863d6cf03567f4e5c1f00d700cbe

Contents?: true

Size: 881 Bytes

Versions: 7

Compression:

Stored size: 881 Bytes

Contents

module Songkickr
  # A class to represent the result hash of an Event search.
  class EventResult
    attr_accessor :page, :total_entries, :results

    # Takes the result hash directly and parses out the page and total entries and finally passes off to the parse_results method to get the results.
    def initialize(result_hash = {})
      results_page = result_hash["resultsPage"]
      
      if results_page
        @page          = results_page["page"]
        @total_entries = results_page["totalEntries"]
        @results       = parse_results results_page["results"]
      end
    end
    
    
    protected
    
      def parse_results(results = {})
        events = []
        if results.include?("event")
          results["event"].each do |event|
            events << Songkickr::Event.new(event)
          end
        end
        
        events
      end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
songkickr-0.3.3 lib/songkickr/event_result.rb
songkickr-0.3.2 lib/songkickr/event_result.rb
songkickr-0.3.1 lib/songkickr/event_result.rb
songkickr-0.3.0 lib/songkickr/event_result.rb
songkickr-0.2.2 lib/songkickr/event_result.rb
songkickr-0.2.1 lib/songkickr/event_result.rb
songkickr-0.2.0 lib/songkickr/event_result.rb