summaryrefslogtreecommitdiff
path: root/data/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-07-03 19:19:41 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-07-03 19:19:41 +0200
commit34857acfa4f7aab4dc17d43db6337d8f72a449ec (patch)
tree794cfca2aaf56725016136c48b21977087a4182b /data/rbot
parent11f1c11250dd27ef02fe78d25d106bd5abbdf57a (diff)
lastfm plugin: cleanup Event initialization and fix missing artist
Diffstat (limited to 'data/rbot')
-rw-r--r--data/rbot/plugins/lastfm.rb32
1 files changed, 18 insertions, 14 deletions
diff --git a/data/rbot/plugins/lastfm.rb b/data/rbot/plugins/lastfm.rb
index 541fc1dc..d99a9526 100644
--- a/data/rbot/plugins/lastfm.rb
+++ b/data/rbot/plugins/lastfm.rb
@@ -17,19 +17,28 @@ require 'rexml/document'
class ::LastFmEvent
def initialize(hash)
- @url = hash[:url] if hash.key? :url
- @date = hash[:date] if hash.key? :date
- @artist = hash[:artist] if hash.key? :artist
- @location = hash[:location] if hash.key? :location
- @description = hash[:description] if hash.key? :description
- @attendance = hash[:attendance] if hash.key? :attendance
+ @url = hash[:url]
+ @date = hash[:date]
+ @location = hash[:location]
+ @description = hash[:description]
+ @attendance = hash[:attendance]
+
+ @artists = hash[:artists]
+
+ if @artists.length > 10 #more than 10 artists and it floods
+ diff = @artists.length - 10
+ @artist_string = @artists[0..10].join(', ')
+ @artist_string << _(" and %{n} more...") % {:n => diff}
+ else
+ @artist_string = @artists.join(', ')
+ end
end
def compact_display
if @attendance
- return "%s %s @ %s (%s attending) %s" % [@date.strftime("%a %b, %d %Y"), @artist, @location, @attendance, @url]
+ return "%s %s @ %s (%s attending) %s" % [@date.strftime("%a %b, %d %Y"), @artist_string, @location, @attendance, @url]
end
- return "%s %s @ %s %s" % [@date.strftime("%a %b, %d %Y"), @artist, @location, @url]
+ return "%s %s @ %s %s" % [@date.strftime("%a %b, %d %Y"), @artist_string, @location, @url]
end
alias :to_s :compact_display
@@ -124,12 +133,7 @@ class LastFmPlugin < Plugin
e.elements.each("artists/artist"){ |a|
artists << a.text
}
- if artists.length > 10 #more than 10 artists and it floods
- diff = artists.length - 10
- artists = artists[0..10]
- artists << _(" and %{n} more...") % {:n => diff}
- end
- h[:artists] = artists.join(", ")
+ h[:artists] = artists
events << LastFmEvent.new(h)
}
events[0...num].each { |event|