Module: Bandsintown::Event::CreationHelpers::ClassMethods

Defined in:
lib/bandsintown/event.rb

Instance Method Summary collapse

Instance Method Details

#parse_artists(artist_data) ⇒ Object

Returns an array of hashes formatted either { :name => name } or { :mbid => mbid } based on each object in artist_data (can be Bandsintown::Artists, Hashes, or Strings)



45
46
47
48
49
50
51
52
53
54
# File 'lib/bandsintown/event.rb', line 45

def parse_artists(artist_data)
  artist_data.map do |artist|
    if artist.is_a?(String)
      { :name => artist }
    else
      hash = artist.to_hash
      hash[:mbid].blank? ? { :name => hash[:name] } : { :mbid => hash[:mbid] }
    end
  end          
end

#parse_datetime(datetime) ⇒ Object

Formats Time/DateTime/Date to ISO 8601 string, or return unmodified if passed as a String.



14
15
16
17
18
19
20
# File 'lib/bandsintown/event.rb', line 14

def parse_datetime(datetime)
  case datetime
  when Time, DateTime then datetime.strftime(ISO_8601_FORMAT)
  when Date then (datetime + 19.hours).strftime(ISO_8601_FORMAT)
  else datetime
  end
end

#parse_venue(venue_data) ⇒ Object

Returns a hash with venue attributes. If bandsintown_id is present this is preferred over location attributes. venue_data can be either a Bandsintown::Venue or a Hash.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bandsintown/event.rb', line 24

def parse_venue(venue_data)
  hash = venue_data.to_hash
  bandsintown_id = hash[:id] || hash[:bandsintown_id]
  venue = if bandsintown_id.blank?
    {
      :name => hash[:name], 
      :address => hash[:address],
      :city => hash[:city], 
      :region => hash[:region],
      :postalcode => hash[:postalcode],
      :country => hash[:country], 
      :latitude => hash[:latitude],
      :longitude => hash[:longitude]
    }
  else
    { :id => bandsintown_id }
  end
  venue.reject { |k,v| v.blank? }
end