Class: Rockstar::Event

Inherits:
Base
  • Object
show all
Defined in:
lib/rockstar/event.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connection, fetch_and_parse, get_instance

Constructor Details

#initialize(id, title) ⇒ Event

Returns a new instance of Event.

Raises:

  • (ArgumentError)


56
57
58
59
60
61
# File 'lib/rockstar/event.rb', line 56

def initialize(id, title)
  raise ArgumentError, "ID is required" if id.blank?
  raise ArgumentError, "Title is required" if title.blank?
  @eid   = id
  @title = title
end

Instance Attribute Details

#artistsObject

Returns the value of attribute artists.



4
5
6
# File 'lib/rockstar/event.rb', line 4

def artists
  @artists
end

#attendanceObject

Returns the value of attribute attendance.



4
5
6
# File 'lib/rockstar/event.rb', line 4

def attendance
  @attendance
end

#cancelledObject

Returns the value of attribute cancelled.



4
5
6
# File 'lib/rockstar/event.rb', line 4

def cancelled
  @cancelled
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/rockstar/event.rb', line 4

def description
  @description
end

#eidObject

Returns the value of attribute eid.



4
5
6
# File 'lib/rockstar/event.rb', line 4

def eid
  @eid
end

#end_dateObject

Returns the value of attribute end_date.



4
5
6
# File 'lib/rockstar/event.rb', line 4

def end_date
  @end_date
end

#headlinersObject

Returns the value of attribute headliners.



4
5
6
# File 'lib/rockstar/event.rb', line 4

def headliners
  @headliners
end

#imagesObject

Returns the value of attribute images.



4
5
6
# File 'lib/rockstar/event.rb', line 4

def images
  @images
end

#reviewsObject

Returns the value of attribute reviews.



4
5
6
# File 'lib/rockstar/event.rb', line 4

def reviews
  @reviews
end

#start_dateObject

Returns the value of attribute start_date.



4
5
6
# File 'lib/rockstar/event.rb', line 4

def start_date
  @start_date
end

#tagObject

Returns the value of attribute tag.



4
5
6
# File 'lib/rockstar/event.rb', line 4

def tag
  @tag
end

#tagsObject

Returns the value of attribute tags.



4
5
6
# File 'lib/rockstar/event.rb', line 4

def tags
  @tags
end

#ticketsObject

Returns the value of attribute tickets.



4
5
6
# File 'lib/rockstar/event.rb', line 4

def tickets
  @tickets
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/rockstar/event.rb', line 4

def title
  @title
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/rockstar/event.rb', line 4

def url
  @url
end

#venueObject

Returns the value of attribute venue.



4
5
6
# File 'lib/rockstar/event.rb', line 4

def venue
  @venue
end

#websiteObject

Returns the value of attribute website.



4
5
6
# File 'lib/rockstar/event.rb', line 4

def website
  @website
end

Class Method Details

.new_from_xml(xml, doc) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rockstar/event.rb', line 9

def new_from_xml(xml, doc)
  e = Event.new(
    (xml).at(:id).inner_html,
    (xml).at(:title).inner_html
  )

  e.artists = []
  xml.search("/artists/artist").each {|a|
    e.artists << a.inner_html
  }

  e.headliners = []
  xml.search("/artists/headliner").each{|h|
    e.headliners <<  h.inner_html
  }

  e.start_date  = Base.parse_time(xml.search("/startDate").inner_html.strip)
  e.end_date    = Base.parse_time(xml.search("/endDate").inner_html.strip)
  e.description = xml.search("/description").inner_html.strip
  e.attendance  = xml.search("/attendance").inner_html.strip.to_i
  e.reviews     = xml.search("/reviews").inner_html.strip.to_i
  e.tag         = xml.search("/tag").inner_html.strip
  e.url         = xml.search("/url").inner_html.strip
  e.website     = xml.search("/website").inner_html.strip
  e.cancelled   = xml.search("/cancelled").inner_html.strip == 1

  e.tickets = []
  xml.search("/tickets/ticket").each{|t|
    e.tickets << t.inner_html
  }

  e.tags = []
  xml.search("/tags/tag").each{|t|
    e.tags << t.inner_html
  }

  e.images = {}
  xml.search('/image').each {|image|
    e.images[image['size']] = image.inner_html if e.images[image['size']].nil?
  }

  e.venue = Venue.new_from_xml(xml.search('/venue'), doc) if xml.search('/venue')

  e
end

Instance Method Details

#image(which = :medium) ⇒ Object

Raises:

  • (ArgumentError)


63
64
65
66
67
68
69
70
# File 'lib/rockstar/event.rb', line 63

def image(which=:medium)
  which = which.to_s
  raise ArgumentError unless ['small', 'medium', 'large', 'extralarge', 'mega'].include?(which)
  if (self.images.nil?)
    load_info
  end
  self.images[which]
end