Class: Twitterscrobble::StatusLine
- Inherits:
-
Object
- Object
- Twitterscrobble::StatusLine
- Defined in:
- lib/twitterscrobble/status_line.rb
Constant Summary collapse
- TWITTER_MAX_MSG_LEN =
140
Instance Method Summary collapse
-
#initialize(track) ⇒ StatusLine
constructor
A new instance of StatusLine.
-
#to_s ⇒ Object
TODO The algorithm to use the maximum number of characters is not the best yet.
Constructor Details
#initialize(track) ⇒ StatusLine
Returns a new instance of StatusLine.
7 8 9 |
# File 'lib/twitterscrobble/status_line.rb', line 7 def initialize(track) @track = track end |
Instance Method Details
#to_s ⇒ Object
TODO The algorithm to use the maximum number of characters is not the best yet. We should also try to cut down single fields that are overly long in favor of not loosing another short field.
Example:
track.name = "A"
track.artist = "Very long artist name that is close to the maximum length of the whole line"
The algorithm below would just return “A”, but a better version would return “Very long … - A”.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/twitterscrobble/status_line.rb', line 24 def to_s status = with_name if with_artist.length <= TWITTER_MAX_MSG_LEN status = with_artist end if with_album.length <= TWITTER_MAX_MSG_LEN status = with_album end if with_url.length <= TWITTER_MAX_MSG_LEN status = with_url end # if status.length > TWITTER_MAX_MSG_LEN # still too long, enforce length restriction # status = "#{status[1, 137]}..." # end status end |