ruby-mpd 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -266,7 +266,4 @@ for a controlled environment needs to be written.
266
266
 
267
267
  * MPD::Song, MPD::Directory.
268
268
  * Make stickers a mixin for Playlist, Song, Directory...
269
- * Namespace queue
270
- * Make parsing per-command (because playlist is an integer in the :status command and
271
- a string in :listplaylists, and :time is an array in status and integer in songs)
272
- * Per command parsing should also skip :directory and :playlist keys inside #songs command.
269
+ * Namespace queue
@@ -2,6 +2,12 @@ require 'time' # required for Time.iso8601
2
2
 
3
3
  class MPD
4
4
  # Parser module, being able to parse messages to and from the MPD daemon format.
5
+ # @todo There are several parser hacks. Time is an array in status and a normal
6
+ # string in MPD::Song, so we do`@time = options.delete(:time) { [nil] }.first`
7
+ # to hack the array return. Playlist names are strings, whilst in status it's
8
+ # and int, so we parse it as an int if it's parsed as non-zero (if it's 0 it's a string)
9
+ # and to fix numeric name playlists (123.m3u), we convert the name to_s inside
10
+ # MPD::Playlist too.
5
11
  module Parser
6
12
  private
7
13
 
@@ -46,7 +52,7 @@ class MPD
46
52
  :decoders, :listplaylistinfo]
47
53
 
48
54
  # Parses key-value pairs into correct class.
49
- def parse_key key, value
55
+ def parse_key(key, value)
50
56
  if INT_KEYS.include? key
51
57
  value.to_i
52
58
  elsif FLOAT_KEYS.include? key
@@ -58,7 +64,6 @@ class MPD
58
64
  elsif key == :playlist && !value.to_i.zero?
59
65
  # doc states it's an unsigned int, meaning if we get 0,
60
66
  # then it's a name string.
61
- # @todo HAXX! what if playlist name is '123'?
62
67
  value.to_i
63
68
  elsif key == :db_update
64
69
  Time.at(value.to_i)
@@ -14,7 +14,7 @@ class MPD
14
14
  attr_accessor :name
15
15
 
16
16
  def initialize(mpd, options)
17
- @name = options.is_a?(Hash) ? options[:playlist] : options.to_s
17
+ @name = options.is_a?(Hash) ? options[:playlist].to_s : options.to_s # convert to_s in case the parser converted to int
18
18
  @mpd = mpd
19
19
  #@last_modified = options[:'last-modified']
20
20
  end
data/lib/ruby-mpd/song.rb CHANGED
@@ -9,7 +9,7 @@ class MPD::Song
9
9
 
10
10
  def initialize(options)
11
11
  @data = {} # allowed fields are @types + :file
12
- @time = options.delete(:time).first #HAXX for array return
12
+ @time = options.delete(:time) { [nil] }.first #HAXX for array return
13
13
  @file = options.delete(:file)
14
14
  @title = options.delete(:title)
15
15
  @artist = options.delete(:artist)
@@ -25,7 +25,11 @@ class MPD::Song
25
25
 
26
26
  # @return [String] A formatted representation of the song length ("1:02")
27
27
  def length
28
- return "#{(@time / 60)}:#{"%02d" % (@time % 60)}"
28
+ if @time.nil?
29
+ '--:--'
30
+ else
31
+ "#{(@time / 60)}:#{"%02d" % (@time % 60)}"
32
+ end
29
33
  end
30
34
 
31
35
  # Pass any unknown calls over to the data hash.
data/ruby-mpd.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
  Gem::Specification.new do |s|
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.name = 'ruby-mpd'
6
- s.version = '0.1.8'
6
+ s.version = '0.2.0'
7
7
  s.homepage = 'https://github.com/archSeer/ruby-mpd'
8
8
  s.authors = ["Blaž Hrastnik"]
9
9
  s.email = ['speed.the.bboy@gmail.com']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mpd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-27 00:00:00.000000000 Z
12
+ date: 2013-01-29 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A powerful, modern and feature complete library for the Music Player
15
15
  Daemon.