Commit 141cc085ef528cd2ac70cd3c94f2a6b05e2ea08c

Anton Maminov 2018-07-31T17:31:06

Rename MPDClient to MPD::Client (#6) * Rename MPDClient to MPD::Client * remove redundants return * Avoid single-line method definitions * nothing special * update readme * add idle example * add rubocop * add .hound.yml * add travis config * add badges to readme * remove rakefile * add rake * revert rakefile * ichange gemspec * add rspec * change travis config * remove rakefile * remove rack-test * add spec * add test * fix rubocop * update badges

1
2
3
4
5
6
7
8
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
diff --git a/.hound.yml b/.hound.yml
new file mode 100644
index 0000000..f534df8
--- /dev/null
+++ b/.hound.yml
@@ -0,0 +1,2 @@
+rubocop:
+  config_file: .rubocop.yml
diff --git a/.rubocop.yml b/.rubocop.yml
new file mode 100644
index 0000000..e75ab57
--- /dev/null
+++ b/.rubocop.yml
@@ -0,0 +1,27 @@
+Metrics/LineLength:
+  Max: 120
+
+Metrics/AbcSize:
+  Enabled: false
+
+Metrics/ClassLength:
+  Enabled: false
+
+Metrics/MethodLength:
+  Enabled: false
+
+Metrics/ModuleLength:
+  Enabled: false
+
+# TODO FIXME
+Metrics/CyclomaticComplexity:
+  Max: 7
+
+Metrics/PerceivedComplexity:
+  Max: 8
+
+Security/Eval:
+  Exclude:
+    - 'lib/mpd_client.rb'
+
+
diff --git a/.ruby-version b/.ruby-version
new file mode 100644
index 0000000..73462a5
--- /dev/null
+++ b/.ruby-version
@@ -0,0 +1 @@
+2.5.1
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..7473163
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: ruby
+script:
+  - rspec
+  - rubocop
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 448728b..bea2963 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,33 +1,37 @@
-# MPDClient CHANGELOG
+# MPD::Client CHANGELOG
 
-### 0.0.6
+## 0.1.0
+
+* Rename `MPDClient` to `MPD::Client`
+
+## 0.0.6
 
 * Fixed readcomments command
 
-### 0.0.5
+## 0.0.5
 
 * Support for mount, umount, listmounts, listneighbors
 * Support for listfiles
 * Support for rangeid, addtagid, cleartagid
 
-### 0.0.4
+## 0.0.4
 
 * Added support for readcomments, toggleoutput, volume
 * Added a mutex protecting execution of MPD commands
 * Automatic reconnect after the server dropped the connection
 
-### 0.0.3
+## 0.0.3
 
 * Support for logging
 * Better support for fetching stickers from MPD
 * Fixed sticker commands
 * Add support for ranges
 
-### 0.0.2
+## 0.0.2
 
 * Support for connecting to unix domain sockets
 * Fixed some bugs
 
-### 0.0.1
+## 0.0.1
 
 * Porting code from mpd-python2
diff --git a/Gemfile b/Gemfile
index 2ff9be7..12e41e1 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,8 +1,15 @@
+# frozen_string_literal: true
+
 source 'https://rubygems.org'
 
 # Specify your gem's dependencies in mpd_client.gemspec
 gemspec
 
-group :development do
+group :development, :test do
   gem 'pry'
+  gem 'rubocop'
+end
+
+group :test do
+  gem 'rspec'
 end
diff --git a/MPD_COMMANDS.md b/MPD_COMMANDS.md
index 7cfe0b1..5d7eb38 100644
--- a/MPD_COMMANDS.md
+++ b/MPD_COMMANDS.md
@@ -1,3 +1,5 @@
+# MPD Commands
+
 * [Status Commands](#status-commands)
 * [Playback Option Commands](#playback-option-commands)
 * [Playback Control Commands](#playback-control-commands)
@@ -10,7 +12,7 @@
 * [Reflection Commands](#reflection-commands)
 * [Client to client](#client-to-client)
 
-### Status Commands ###
+## Status Commands
 
 ---
 `clearerror => fetch_nothing`
@@ -27,7 +29,7 @@
 
 > Waits until there is a noteworthy change in one or more of MPD's subsystems. As soon as there is one, it lists all changed systems in a line in the format changed: `SUBSYSTEM`, where `SUBSYSTEM` is one of the following:
 
-> * `database`: the song database has been modified after update.
+* `database`: the song database has been modified after update.
 * `update`: a database update has started or finished. If the database was modified during the update, the database event is also emitted.
 * `stored_playlist`: a stored playlist has been modified, renamed, created or deleted
 * `playlist`: the current playlist has been modified
@@ -39,21 +41,19 @@
 * `subscription`: a client has subscribed or unsubscribed to a channel
 * `message`: a message was received on a channel this client is subscribed to; this event is only emitted when the queue is empty
 
-> While a client is waiting for `idle` results, the server disables timeouts, allowing a client to wait for events as long as mpd runs. The `idle` command can be canceled by sending the command `noidle` (no other commands are allowed). MPD will then leave `idle` mode and print results immediately; might be empty at this time.
+While a client is waiting for `idle` results, the server disables timeouts, allowing a client to wait for events as long as mpd runs. The `idle` command can be canceled by sending the command `noidle` (no other commands are allowed). MPD will then leave `idle` mode and print results immediately; might be empty at this time.
 
-> If the optional `SUBSYSTEMS` argument is used, MPD will only send notifications when something changed in one of the specified subsytems.
+If the optional `SUBSYSTEMS` argument is used, MPD will only send notifications when something changed in one of the specified subsytems.
 
 ---
 `noidle`
 
->
-
 ---
 `status => "fetch_object`
 
 > Reports the current status of the player and the volume level.
 
-> * `volume`: 0-100
+* `volume`: 0-100
 * `repeat`: 0 or 1
 * `random`: 0 or 1
 * `single`: 0 or 1
@@ -80,14 +80,14 @@
 
 > Displays statistics.
 
-> * `artists`: number of artists
+* `artists`: number of artists
 * `songs`: number of albums
 * `uptime`: daemon uptime in seconds
 * `db_playtime`: sum of all song times in the db
 * `db_update`: last db update in UNIX time
 * `playtime`: time length of music played
 
-### Playback Option Commands ###
+## Playback Option Commands
 
 ---
 `consume {STATE} => fetch_nothing`
@@ -102,7 +102,7 @@
 ---
 `mixrampdb {deciBels} => fetch_nothing`
 
-> Sets the threshold at which songs will be overlapped. Like crossfading but doesn't fade the track volume, just overlaps. The songs need to have MixRamp tags added by an external tool. 0dB is the normalized maximum volume so use negative values, I prefer -17dB. In the absence of mixramp tags crossfading will be used. See http://sourceforge.net/projects/mixramp
+> Sets the threshold at which songs will be overlapped. Like crossfading but doesn't fade the track volume, just overlaps. The songs need to have MixRamp tags added by an external tool. 0dB is the normalized maximum volume so use negative values, I prefer -17dB. In the absence of mixramp tags crossfading will be used. See [mixramp](https://sourceforge.net/projects/mixramp/)
 
 ---
 `mixrampdelay {SECONDS} => fetch_nothing`
@@ -134,9 +134,9 @@
 
 > Sets the replay gain mode. One of `off`, `track`, `album`, `auto`.
 
-> Changing the mode during playback may take several seconds, because the new settings does not affect the buffered data.
+Changing the mode during playback may take several seconds, because the new settings does not affect the buffered data.
 
-> This command triggers the options idle event.
+This command triggers the options idle event.
 
 ---
 `replay_gain_status => fetch_item`
@@ -148,7 +148,7 @@
 
 > Changes volume by amount `CHANGE`.
 
-### Playback Control Commands ###
+## Playback Control Commands
 
 ---
 `next => fetch_nothing`
@@ -196,8 +196,7 @@
 
 > Stops playing.
 
-
-### Playlist Commands ###
+## Playlist Commands
 
 ---
 `add {URI} => fetch_nothing`
@@ -209,7 +208,7 @@
 
 > Adds a song to the playlist (non-recursive) and returns the song id.
 
-> `URI` is always a single file or URL.
+`URI` is always a single file or URL.
 
 ---
 `clear => fetch_nothing`
@@ -240,7 +239,6 @@
 `playlist => fetch_playlist`
 
 > Displays the current playlist.
-
 > > **Note**: Do not use this, instead use `playlistinfo`.
 
 ---
@@ -268,21 +266,21 @@
 
 > Displays changed songs currently in the playlist since `VERSION`.
 
-> To detect songs that were deleted at the end of the playlist, use `playlistlength` returned by status command.
+To detect songs that were deleted at the end of the playlist, use `playlistlength` returned by status command.
 
 ---
 `plchangesposid {VERSION} => fetch_changes`
 
 > Displays changed songs currently in the playlist since `VERSION`. This function only returns the position and the id of the changed song, not the complete metadata. This is more bandwidth efficient.
 
-> To detect songs that were deleted at the end of the playlist, use `playlistlength` returned by status command.
+To detect songs that were deleted at the end of the playlist, use `playlistlength` returned by status command.
 
 ---
 `prio {PRIORITY} {START:END...} => fetch_nothing`
 
 > Set the priority of the specified songs. A higher priority means that it will be played first when "random" mode is enabled.
 
-> A priority is an integer between 0 and 255. The default priority of new songs is 0.
+A priority is an integer between 0 and 255. The default priority of new songs is 0.
 
 ---
 `prioid {PRIORITY} {ID...} => fetch_nothing`
@@ -319,7 +317,7 @@
 
 > Removes `TAG` from the specified `SONGID`. If `TAG` is not specified, then all tag values will be removed. Editing song tags is only possible for remote songs.
 
-### Stored Playlist Commands ###
+## Stored Playlist Commands
 
 Playlists are stored inside the configured playlist directory. They are addressed with their file name (without the directory and without the .m3u suffix).
 
@@ -340,7 +338,7 @@ Some of the commands described in this section can be used to run playlist plugi
 
 > Prints a list of the playlist directory.
 
-> After each playlist name the server sends its last modification time as attribute "Last-Modified" in ISO 8601 format. To avoid problems due to clock differences between clients and the server, clients should not compare this value with their local clock.
+After each playlist name the server sends its last modification time as attribute "Last-Modified" in ISO 8601 format. To avoid problems due to clock differences between clients and the server, clients should not compare this value with their local clock.
 
 ---
 `load {NAME} [START:END] => fetch_nothing`
@@ -352,7 +350,7 @@ Some of the commands described in this section can be used to run playlist plugi
 
 > Adds `URI` to the playlist `NAME.m3u`.
 
-> `NAME.m3u` will be created if it does not exist.
+`NAME.m3u` will be created if it does not exist.
 
 ---
 `playlistclear {NAME} => fetch_nothing`
@@ -384,7 +382,7 @@ Some of the commands described in this section can be used to run playlist plugi
 
 > Saves the current playlist to `NAME.m3u` in the playlist directory.
 
-### Database Commands ###
+## Database Commands
 
 ---
 `count {TAG} {NEEDLE} => fetch_object`
@@ -406,7 +404,7 @@ Some of the commands described in this section can be used to run playlist plugi
 
 > Lists all tags of the specified type. `TYPE` can be any tag supported by MPD or file.
 
-> `ARTIST` is an optional parameter when type is album, this specifies to list albums by an artist.
+`ARTIST` is an optional parameter when type is album, this specifies to list albums by an artist.
 
 ---
 `listall [URI] => fetch_database`
@@ -423,14 +421,14 @@ Some of the commands described in this section can be used to run playlist plugi
 
 > Lists the contents of the directory `URI`, including files are not recognized by `MPD`. `URI` can be a path relative to the music directory or an `URI` understood by one of the storage plugins. The response contains at least one line for each directory entry with the prefix `"file: "` or  `"directory: "`, and may be followed by file attributes such as `"Last-Modified"` and `"size"`.
 
-> For example, `smb://SERVER` returns a list of all shares on the given SMB/CIFS server; `nfs://servername/path` obtains a directory listing from the NFS server.
+For example, `smb://SERVER` returns a list of all shares on the given SMB/CIFS server; `nfs://servername/path` obtains a directory listing from the NFS server.
 
 ---
 `lsinfo [URI] => fetch_database`
 
 > Lists the contents of the directory `URI`.
 
-> When listing the root directory, this currently returns the list of stored playlists. This behavior is deprecated; use `listplaylists` instead.
+When listing the root directory, this currently returns the list of stored playlists. This behavior is deprecated; use `listplaylists` instead.
 
 > Clients that are connected via UNIX domain socket may use this command to read the tags of an arbitrary local file (`URI` beginning with "file:///").
 
@@ -444,25 +442,25 @@ Some of the commands described in this section can be used to run playlist plugi
 
 > Searches for any song that contains `WHAT` in tag `TYPE` and adds them to current playlist.
 
-> Parameters have the same meaning as for `find`, except that search is not case sensitive.
+Parameters have the same meaning as for `find`, except that search is not case sensitive.
 
 ---
 `searchaddpl {NAME} {TYPE} {WHAT} [...] => fetch_nothing`
 
 > Searches for any song that contains `WHAT` in tag `TYPE` and adds them to the playlist named `NAME`.
 
-> If a playlist by that name doesn't exist it is created.
+If a playlist by that name doesn't exist it is created.
 
-> Parameters have the same meaning as for find, except that search is not case sensitive.
+Parameters have the same meaning as for find, except that search is not case sensitive.
 
 ---
 `update [URI] => fetch_item`
 
 > Updates the music database: find new files, remove deleted files, update modified files.
 
-> `URI` is a particular directory or song/file to update. If you do not specify it, everything is updated.
+`URI` is a particular directory or song/file to update. If you do not specify it, everything is updated.
 
-> Prints "updating_db: JOBID" where JOBID is a positive number identifying the update job. You can read the current job id in the status response.
+Prints "updating_db: JOBID" where JOBID is a positive number identifying the update job. You can read the current job id in the status response.
 
 ---
 `rescan [URI] => fetch_item`
@@ -474,11 +472,11 @@ Some of the commands described in this section can be used to run playlist plugi
 
 > Read "comments" (i.e. key-value pairs) from the file specified by `URI`. This `URI` can be a path relative to the music directory or a URL in the form `file:///foo/bar.ogg`.
 
-> The response consists of lines in the form "KEY: VALUE". Comments with suspicious characters (e.g. newlines) are ignored silently.
+The response consists of lines in the form "KEY: VALUE". Comments with suspicious characters (e.g. newlines) are ignored silently.
 
-> The meaning of these depends on the codec, and not all decoder plugins support it.  For example, on Ogg files, this lists the Vorbis comments.
+The meaning of these depends on the codec, and not all decoder plugins support it.  For example, on Ogg files, this lists the Vorbis comments.
 
-### Mounts and neighbors ###
+## Mounts and neighbors
 
 A "storage" provides access to files in the directory tree. The most basic storage plugin is a "local" storage plugin which accesses the local file system, and there are plugins to access NFS and SMB servers.
 
@@ -504,7 +502,7 @@ Multiple storages can be "mounted" together, similar to the `mount` command on m
 
 > Queries a list of "neighbors" (e.g. accessible file servers on the local net).  Items on that list may be used with the `mount` command.
 
-### Sticker Commands ###
+## Sticker Commands
 
 "Stickers" are pieces of information attached to existing MPD objects (e.g. song files, directories, albums). Clients can create arbitrary name/value pairs. MPD itself does not assume any special meaning in them.
 
@@ -539,7 +537,7 @@ Objects which may have stickers are addressed by their object type ("song" for s
 
 > Searches the sticker database for stickers with the specified name, below the specified directory (`URI`). For each matching song, it prints the URI and that one sticker's value.
 
-### Connection Commands ###
+## Connection Commands
 
 ---
 `close`
@@ -583,20 +581,18 @@ Objects which may have stickers are addressed by their object type ("song" for s
 
 > Turns an output on or off, depending on the current state.
 
-
-### Reflection Commands ###
+## Reflection Commands
 
 ---
 `config => fetch_item`
 
 > Dumps configuration values that may be interesting for the client. This command is only permitted to "local" clients (connected via UNIX domain socket).
 
-> The following response attributes are available:
+The following response attributes are available:
 
->
-| Name 	             | Description                              |
-| ------------------ | ---------------------------------------- |
-| music_directory    | The absolute path of the music directory |
+| Name | Description |
+| --- | --- |
+| music_directory | The absolute path of the music directory |
 
 ---
 `commands => fetch_list`
@@ -623,7 +619,7 @@ Objects which may have stickers are addressed by their object type ("song" for s
 
 > Print a list of decoder plugins, followed by their supported suffixes and MIME types.
 
-### Client to client ###
+## Client to client
 
 Clients can communicate with each others over "channels". A channel is created by a client subscribing to it. More than one client can be subscribed to a channel at a time; all of them will receive the messages which get sent to it.
 
diff --git a/README.md b/README.md
index afff92a..bfd5ed9 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,7 @@
-# MPDClient
+# MPD::Client
+
+[![Build Status](https://badgen.net/travis/mamantoha/mpd_client)](https://travis-ci.org/mamantoha/mpd_client)
+[![Gem Version](https://badge.fury.io/rb/mpd_client.svg)](https://badge.fury.io/rb/mpd_client)
 
 Yet another Music Player Daemon (MPD) client library written entirely in Ruby.
 `mpd_client` is a Ruby port of the [python-mpd](https://github.com/Mic92/python-mpd2) library.
@@ -13,24 +16,25 @@ gem 'mpd_client'
 
 And then execute:
 
-```
-$ bundle
+```console
+bundle
 ```
 
 Or install it yourself as:
 
-```
-$ gem install mpd_client
+```console
+gem install mpd_client
 ```
 
 ## Usage
-All functionality is contained in the `MPDClient` class. Creating an instance of this class is as simple as:
+
+All functionality is contained in the `MPD::Client` class. Creating an instance of this class is as simple as:
 
 ```ruby
-client = MPDClient.new
+client = MPD::Client.new
 ```
 
-Once you have an instance of the `MPDClient` class, start by connecting to the server:
+Once you have an instance of the `MPD::Client` class, start by connecting to the server:
 
 ```ruby
 client.connect('localhost', 6600)
@@ -78,28 +82,28 @@ client.delete([10,])
 
 ### Logging
 
-Default logger for all MPDClient instances:
+Default logger for all MPD::Client instances:
 
 ```ruby
 require 'logger'
 require 'mpd_client'
 
-MPDClient.log = Logger.new($stderr)
+MPD::Client.log = Logger.new($stderr)
 
-client = MPDClient.new
+client = MPD::Client.new
 ```
 
-Sets the logger used by this instance of MPDClient:
+Sets the logger used by this instance of MPD::Client:
 
 ```ruby
 require 'logger'
 require 'mpd_client'
 
-client = MPDClient.new
+client = MPD::Client.new
 client.log = Logger.new($stderr)
 ```
 
-For more information about logging configuration, see http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html
+For more information about logging configuration, see [Logger](https://ruby-doc.org/stdlib-2.5.1/libdoc/logger/rdoc/Logger.html)
 
 ## Development
 
@@ -117,6 +121,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To 
 
 ## License and Author
 
-Copyright (c) 2013-2017 by Anton Maminov
+Copyright (c) 2013-2018 by Anton Maminov
 
 This library is distributed under the MIT license.  Please see the LICENSE file.
diff --git a/Rakefile b/Rakefile
deleted file mode 100644
index f57ae68..0000000
--- a/Rakefile
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/usr/bin/env rake
-require "bundler/gem_tasks"
diff --git a/bin/console b/bin/console
index dcca0cf..ea9e5bf 100755
--- a/bin/console
+++ b/bin/console
@@ -1,7 +1,8 @@
 #!/usr/bin/env ruby
+# frozen_string_literal: true
 
-require "bundler/setup"
-require "mpd_client"
+require 'bundler/setup'
+require 'mpd_client'
 
 # You can add fixtures and/or initialization code here to make experimenting
 # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "mpd_client"
 # require "pry"
 # Pry.start
 
-require "irb"
+require 'irb'
 IRB.start
diff --git a/examples/Gemfile b/examples/Gemfile
index 22aa2bf..38b6666 100644
--- a/examples/Gemfile
+++ b/examples/Gemfile
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 source 'https://rubygems.org'
 
 gem 'mpd_client', path: '../'
diff --git a/examples/idle.rb b/examples/idle.rb
new file mode 100644
index 0000000..27674df
--- /dev/null
+++ b/examples/idle.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+require 'bundler'
+Bundler.setup :default
+
+require 'logger'
+require 'mpd_client'
+
+client = MPD::Client.new
+
+client = MPD::Client.new
+client.log = Logger.new($stderr)
+
+client.connect('localhost', 6600)
+
+# Lists all changed systems:
+# database, update, stored_playlist, playlist, player, mixer, output, options, sticker, subscription, message
+#
+subsystems = %w[player playlist]
+
+loop do
+  resp = client.idle(*subsystems)
+  puts resp
+end
+
+client.close
+client.disconnect
diff --git a/examples/range.rb b/examples/range.rb
index 3041a08..3530ab2 100644
--- a/examples/range.rb
+++ b/examples/range.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require 'bundler'
 Bundler.setup :default
 
@@ -5,16 +7,16 @@ require 'pp'
 require 'logger'
 require 'mpd_client'
 
-MPDClient.log = Logger.new($stderr)
+MPD::Client.log = Logger.new($stderr)
 
-client = MPDClient.new
+client = MPD::Client.new
 client.connect('localhost', 6600)
 
 # delete all songs from the current playlist, except for the firts ten
-client.delete([10,])
+client.delete([10])
 
 # move the first three songs after the fifth number in the playlist
 client.move([0, 3], 5)
 
 # print songs form 5 to 10
-client.playlistinfo([5, 10]).each{ |s| puts "#{s['artist']} - #{s['title']}"}
+client.playlistinfo([5, 10]).each { |s| puts "#{s['artist']} - #{s['title']}" }
diff --git a/examples/rangeid.rb b/examples/rangeid.rb
index 350dfdc..925f2a0 100644
--- a/examples/rangeid.rb
+++ b/examples/rangeid.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require 'bundler'
 Bundler.setup :default
 
@@ -5,9 +7,9 @@ require 'pp'
 require 'logger'
 require 'mpd_client'
 
-MPDClient.log = Logger.new($stderr)
+MPD::Client.log = Logger.new($stderr)
 
-client = MPDClient.new
+client = MPD::Client.new
 client.connect('localhost', 6600)
 
 # Get id of the first song in the playllist
@@ -16,7 +18,7 @@ pp "#{song['artist']} - #{song['title']}"
 song_id = song['id']
 
 # Specifies the portion of the song that shall be played
-client.rangeid(song_id, [60,70])
+client.rangeid(song_id, [60, 70])
 
 # Play the playlist at song 1
 client.play(1)
diff --git a/examples/search_and_replace_playlist.rb b/examples/search_and_replace_playlist.rb
index b692c79..ce51034 100644
--- a/examples/search_and_replace_playlist.rb
+++ b/examples/search_and_replace_playlist.rb
@@ -1,24 +1,26 @@
+# frozen_string_literal: true
+
 require 'bundler'
 Bundler.setup :default
 
 require 'logger'
 require 'mpd_client'
 
-# MPDClient.log = Logger.new($stderr)
+# MPD::Client.log = Logger.new($stderr)
 
-client = MPDClient.new
+client = MPD::Client.new
 
 type = ARGV[0]
 what = ARGV[1]
 
-client = MPDClient.new
+client = MPD::Client.new
 client.log = Logger.new($stderr)
 
 # Connecting to the server
 client.connect('localhost', 6600)
 
 puts "MPD version: #{client.mpd_version}"
-puts "mpd_client version: #{MPDClient::VERSION}"
+puts "mpd_client version: #{MPD::Client::VERSION}"
 
 client.stop
 client.clear # clear the current playlist
@@ -32,7 +34,7 @@ songs = client.search(type, what)
 
 client.command_list_ok_begin # start a command list to speed up operations
 songs.each do |song|
-  client.add(song['file']) if song.has_key?('file')
+  client.add(song['file']) if song.key?('file')
 end
 client.command_list_end
 
diff --git a/examples/stickers.rb b/examples/stickers.rb
index ce99b47..6908f08 100644
--- a/examples/stickers.rb
+++ b/examples/stickers.rb
@@ -1,26 +1,29 @@
+# frozen_string_literal: true
+
 require 'bundler'
 Bundler.setup :default
 
 require 'logger'
 require 'mpd_client'
 
-MPDClient.log = Logger.new($stderr)
+MPD::Client.log = Logger.new($stderr)
 
 # Stickers
 # http://www.musicpd.org/doc/protocol/ch03s07.html
 
-client = MPDClient.new
+client = MPD::Client.new
 
 # Connecting to the server
 client.connect('/run/mpd/socket')
 
 puts "MPD version: #{client.mpd_version}"
-puts "mpd_client version: #{MPDClient::VERSION}"
+puts "mpd_client version: #{MPD::Client::VERSION}"
 
-uri = "world/j/Jane Air/2012.Иллюзия полёта/12. Любить любовь.ogg"
+uri = 'world/j/Jane Air/2012.Иллюзия полёта/12. Любить любовь.ogg'
 
 # sticker set {TYPE} {URI} {NAME} {VALUE}
-#   Adds a sticker value to the specified object. If a sticker item with that name already exists, it is replaced.
+#   Adds a sticker value to the specified object.
+#   If a sticker item with that name already exists, it is replaced.
 #
 client.sticker_set('song', uri, 'rating', '1')
 
@@ -41,7 +44,8 @@ puts client.sticker_list('song', uri)
 puts client.sticker_find('song', '/', 'rating')
 
 # sticker delete {TYPE} {URI} [NAME]
-#   Deletes a sticker value from the specified object. If you do not specify a sticker name, all sticker values are deleted.
+#   Deletes a sticker value from the specified object.
+#   If you do not specify a sticker name, all sticker values are deleted.
 #
 client.sticker_delete('song', uri, 'rating')
 
diff --git a/lib/mpd_client.rb b/lib/mpd_client.rb
index 8b28c7a..e371948 100644
--- a/lib/mpd_client.rb
+++ b/lib/mpd_client.rb
@@ -1,423 +1,466 @@
+# frozen_string_literal: true
+
 require 'socket'
-require "mpd_client/version"
-
-HELLO_PREFIX = "OK MPD "
-ERROR_PREFIX = "ACK "
-SUCCESS = "OK"
-NEXT = "list_OK"
-
-# MPD changelog: http://git.musicpd.org/cgit/master/mpd.git/plain/NEWS
-# http://www.musicpd.org/doc/protocol/command_reference.html
-# http://git.musicpd.org/cgit/cirrus/mpd.git/plain/doc/protocol.xml
-#
-COMMANDS = {
-  # Status Commands
-  "clearerror"         => "fetch_nothing",
-  "currentsong"        => "fetch_object",
-  "idle"               => "fetch_list",
-  "noidle"             => "",
-  "status"             => "fetch_object",
-  "stats"              => "fetch_object",
-  # Playback Option Commands
-  "consume"            => "fetch_nothing",
-  "crossfade"          => "fetch_nothing",
-  "mixrampdb"          => "fetch_nothing",
-  "mixrampdelay"       => "fetch_nothing",
-  "random"             => "fetch_nothing",
-  "repeat"             => "fetch_nothing",
-  "setvol"             => "fetch_nothing",
-  "single"             => "fetch_nothing",
-  "replay_gain_mode"   => "fetch_nothing",
-  "replay_gain_status" => "fetch_item",
-  "volume"             => "fetch_nothing",
-  # Playback Control Commands
-  "next"               => "fetch_nothing",
-  "pause"              => "fetch_nothing",
-  "play"               => "fetch_nothing",
-  "playid"             => "fetch_nothing",
-  "previous"           => "fetch_nothing",
-  "seek"               => "fetch_nothing",
-  "seekid"             => "fetch_nothing",
-  "seekcur"            => "fetch_nothing",
-  "stop"               => "fetch_nothing",
-  # Playlist Commands
-  "add"                => "fetch_nothing",
-  "addid"              => "fetch_item",
-  "addtagid"           => "fetch_nothing",
-  "cleartagid"         => "fetch_nothing",
-  "clear"              => "fetch_nothing",
-  "delete"             => "fetch_nothing",
-  "deleteid"           => "fetch_nothing",
-  "move"               => "fetch_nothing",
-  "moveid"             => "fetch_nothing",
-  "playlist"           => "fetch_playlist",
-  "playlistfind"       => "fetch_songs",
-  "playlistid"         => "fetch_songs",
-  "playlistinfo"       => "fetch_songs",
-  "playlistsearch"     => "fetch_songs",
-  "plchanges"          => "fetch_songs",
-  "plchangesposid"     => "fetch_changes",
-  "prio"               => "fetch_nothing",
-  "prioid"             => "fetch_nothing",
-  "rangeid"            => "fetch_nothing",
-  "shuffle"            => "fetch_nothing",
-  "swap"               => "fetch_nothing",
-  "swapid"             => "fetch_nothing",
-  # Stored Playlist Commands
-  "listplaylist"       => "fetch_list",
-  "listplaylistinfo"   => "fetch_songs",
-  "listplaylists"      => "fetch_playlists",
-  "load"               => "fetch_nothing",
-  "playlistadd"        => "fetch_nothing",
-  "playlistclear"      => "fetch_nothing",
-  "playlistdelete"     => "fetch_nothing",
-  "playlistmove"       => "fetch_nothing",
-  "rename"             => "fetch_nothing",
-  "rm"                 => "fetch_nothing",
-  "save"               => "fetch_nothing",
-  # Database Commands
-  "count"              => "fetch_object",
-  "find"               => "fetch_songs",
-  "findadd"            => "fetch_nothing",
-  "list"               => "fetch_list",
-  "listall"            => "fetch_database",
-  "listallinfo"        => "fetch_database",
-  "listfiles"          => "fetch_database",
-  "lsinfo"             => "fetch_database",
-  "search"             => "fetch_songs",
-  "searchadd"          => "fetch_nothing",
-  "searchaddp1"        => "fetch_nothing",
-  "update"             => "fetch_item",
-  "rescan"             => "fetch_item",
-  "readcomments"       => "fetch_object",
-  # Mounts and neighbors
-  "mount"              => "fetch_nothing",
-  "unmount"            => "fetch_nothing",
-  "listmounts"         => "fetch_mounts",
-  "listneighbors"      => "fetch_neighbors",
-  # Sticker Commands
-  "sticker get"        => "fetch_sticker",
-  "sticker set"        => "fetch_nothing",
-  "sticker delete"     => "fetch_nothing",
-  "sticker list"       => "fetch_stickers",
-  "sticker find"       => "fetch_songs",
-  # Connection Commands
-  "close"              => "",
-  "kill"               => "",
-  "password"           => "fetch_nothing",
-  "ping"               => "fetch_nothing",
-  # Audio Output Commands
-  "disableoutput"      => "fetch_nothing",
-  "enableoutput"       => "fetch_nothing",
-  "outputs"            => "fetch_outputs",
-  "toggleoutput"       => "fetch_nothing",
-  # Reflection Commands
-  "config"             => "fetch_item",
-  "commands"           => "fetch_list",
-  "notcommands"        => "fetch_list",
-  "tagtypes"           => "fetch_list",
-  "urlhandlers"        => "fetch_list",
-  "decoders"           => "fetch_plugins",
-  # Client To Client
-  "subscribe"          => "fetch_nothing",
-  "unsubscribe"        => "fetch_nothing",
-  "channels"           => "fetch_list",
-  "readmessages"       => "fetch_messages",
-  "sendmessage"        => "fetch_nothing"
-}
-
-# The MPDClient library is used for interactions with a MPD.
-#
-# == Example
-#
-#   require 'mpd_client'
-#   require 'logger'
-#
-#   client = MPDClient.new
-#   client.log = Logger.new($stderr)
-#   client.connect('/var/run/mpd/socket')
-#
-class MPDClient
-  attr_reader :mpd_version
-
-  class << self
-    # Default logger for all MPDClient instances
-    #
-    #   MPDClient.log = Logger.new($stderr)
-    #
-    attr_accessor :log
-
-    def add_command(name, retval)
-      escaped_name = name.gsub(' ', '_')
-      define_method escaped_name.to_sym do |*args|
-        execute(name, *args, retval)
+require 'mpd_client/version'
+
+module MPD
+  HELLO_PREFIX = 'OK MPD '
+  ERROR_PREFIX = 'ACK '
+  SUCCESS = 'OK'
+  NEXT = 'list_OK'
+
+  # MPD changelog: http://git.musicpd.org/cgit/master/mpd.git/plain/NEWS
+  # http://www.musicpd.org/doc/protocol/command_reference.html
+  # http://git.musicpd.org/cgit/cirrus/mpd.git/plain/doc/protocol.xml
+  COMMANDS = {
+    # Status Commands
+    'clearerror'         => 'fetch_nothing',
+    'currentsong'        => 'fetch_object',
+    'idle'               => 'fetch_list',
+    'noidle'             => '',
+    'status'             => 'fetch_object',
+    'stats'              => 'fetch_object',
+    # Playback Option Commands
+    'consume'            => 'fetch_nothing',
+    'crossfade'          => 'fetch_nothing',
+    'mixrampdb'          => 'fetch_nothing',
+    'mixrampdelay'       => 'fetch_nothing',
+    'random'             => 'fetch_nothing',
+    'repeat'             => 'fetch_nothing',
+    'setvol'             => 'fetch_nothing',
+    'single'             => 'fetch_nothing',
+    'replay_gain_mode'   => 'fetch_nothing',
+    'replay_gain_status' => 'fetch_item',
+    'volume'             => 'fetch_nothing',
+    # Playback Control Commands
+    'next'               => 'fetch_nothing',
+    'pause'              => 'fetch_nothing',
+    'play'               => 'fetch_nothing',
+    'playid'             => 'fetch_nothing',
+    'previous'           => 'fetch_nothing',
+    'seek'               => 'fetch_nothing',
+    'seekid'             => 'fetch_nothing',
+    'seekcur'            => 'fetch_nothing',
+    'stop'               => 'fetch_nothing',
+    # Playlist Commands
+    'add'                => 'fetch_nothing',
+    'addid'              => 'fetch_item',
+    'addtagid'           => 'fetch_nothing',
+    'cleartagid'         => 'fetch_nothing',
+    'clear'              => 'fetch_nothing',
+    'delete'             => 'fetch_nothing',
+    'deleteid'           => 'fetch_nothing',
+    'move'               => 'fetch_nothing',
+    'moveid'             => 'fetch_nothing',
+    'playlist'           => 'fetch_playlist',
+    'playlistfind'       => 'fetch_songs',
+    'playlistid'         => 'fetch_songs',
+    'playlistinfo'       => 'fetch_songs',
+    'playlistsearch'     => 'fetch_songs',
+    'plchanges'          => 'fetch_songs',
+    'plchangesposid'     => 'fetch_changes',
+    'prio'               => 'fetch_nothing',
+    'prioid'             => 'fetch_nothing',
+    'rangeid'            => 'fetch_nothing',
+    'shuffle'            => 'fetch_nothing',
+    'swap'               => 'fetch_nothing',
+    'swapid'             => 'fetch_nothing',
+    # Stored Playlist Commands
+    'listplaylist'       => 'fetch_list',
+    'listplaylistinfo'   => 'fetch_songs',
+    'listplaylists'      => 'fetch_playlists',
+    'load'               => 'fetch_nothing',
+    'playlistadd'        => 'fetch_nothing',
+    'playlistclear'      => 'fetch_nothing',
+    'playlistdelete'     => 'fetch_nothing',
+    'playlistmove'       => 'fetch_nothing',
+    'rename'             => 'fetch_nothing',
+    'rm'                 => 'fetch_nothing',
+    'save'               => 'fetch_nothing',
+    # Database Commands
+    'count'              => 'fetch_object',
+    'find'               => 'fetch_songs',
+    'findadd'            => 'fetch_nothing',
+    'list'               => 'fetch_list',
+    'listall'            => 'fetch_database',
+    'listallinfo'        => 'fetch_database',
+    'listfiles'          => 'fetch_database',
+    'lsinfo'             => 'fetch_database',
+    'search'             => 'fetch_songs',
+    'searchadd'          => 'fetch_nothing',
+    'searchaddp1'        => 'fetch_nothing',
+    'update'             => 'fetch_item',
+    'rescan'             => 'fetch_item',
+    'readcomments'       => 'fetch_object',
+    # Mounts and neighbors
+    'mount'              => 'fetch_nothing',
+    'unmount'            => 'fetch_nothing',
+    'listmounts'         => 'fetch_mounts',
+    'listneighbors'      => 'fetch_neighbors',
+    # Sticker Commands
+    'sticker get'        => 'fetch_sticker',
+    'sticker set'        => 'fetch_nothing',
+    'sticker delete'     => 'fetch_nothing',
+    'sticker list'       => 'fetch_stickers',
+    'sticker find'       => 'fetch_songs',
+    # Connection Commands
+    'close'              => '',
+    'kill'               => '',
+    'password'           => 'fetch_nothing',
+    'ping'               => 'fetch_nothing',
+    # Audio Output Commands
+    'disableoutput'      => 'fetch_nothing',
+    'enableoutput'       => 'fetch_nothing',
+    'outputs'            => 'fetch_outputs',
+    'toggleoutput'       => 'fetch_nothing',
+    # Reflection Commands
+    'config'             => 'fetch_item',
+    'commands'           => 'fetch_list',
+    'notcommands'        => 'fetch_list',
+    'tagtypes'           => 'fetch_list',
+    'urlhandlers'        => 'fetch_list',
+    'decoders'           => 'fetch_plugins',
+    # Client To Client
+    'subscribe'          => 'fetch_nothing',
+    'unsubscribe'        => 'fetch_nothing',
+    'channels'           => 'fetch_list',
+    'readmessages'       => 'fetch_messages',
+    'sendmessage'        => 'fetch_nothing'
+  }.freeze
+
+  # The `MPD::Client` is used for interactions with a MPD server.
+  #
+  # Example:
+  #
+  # ```ruby
+  # require 'mpd_client'
+  # require 'logger'
+  #
+  # client = MPD::Client.new
+  # client.log = Logger.new($stderr)
+  # client.connect('/var/run/mpd/socket')
+  # ```
+  class Client
+    attr_reader :mpd_version
+
+    class << self
+      # Default logger for all `MPD::Client`` instances
+      #
+      # ```ruby
+      # MPD::Client.log = Logger.new($stderr)
+      # ```
+      attr_accessor :log
+
+      def connect(host = 'localhost', port = 6600)
+        client = MPD::Client.new
+        client.connect(host, port)
+
+        client
+      end
+
+      def add_command(name, retval)
+        escaped_name = name.tr(' ', '_')
+        define_method escaped_name.to_sym do |*args|
+          ensure_connected
+
+          execute(name, *args, retval)
+        end
+      end
+
+      def remove_command(name)
+        raise "Can't remove not existent '#{name}' command" unless method_defined? name.to_sym
+        remove_method name.to_sym
       end
     end
 
-    def remove_command(name)
-      raise "Can't remove not existent '#{name}' command" unless method_defined? name.to_sym
-      remove_method name.to_sym
+    def initialize
+      @mutex = Mutex.new
+      reset
     end
-  end
 
-  def initialize
-    @mutex = Mutex.new
-    reset
-  end
+    def connect(host = 'localhost', port = 6600)
+      @host = host
+      @port = port
 
-  def connect(host = 'localhost', port = 6600)
-    @host = host
-    @port = port
-    reconnect
-  end
+      reconnect
+    end
+
+    def reconnect
+      log&.info("MPD (re)connect #{@host}, #{@port}")
+
+      @socket = if @host.start_with?('/')
+                  UNIXSocket.new(@host)
+                else
+                  TCPSocket.new(@host, @port)
+                end
 
-  def reconnect
-    log.info("MPD (re)connect #{@host}, #{@port}") if log
-    if @host.start_with?('/')
-      @socket = UNIXSocket.new(@host)
-      hello
-    else
-      @socket = TCPSocket.new(@host, @port)
       hello
+      @connected = true
     end
-  end
 
-  def disconnect
-    log.info("MPD disconnect") if log
-    @socket.close
-    reset
-  end
+    def disconnect
+      log&.info('MPD disconnect')
+      @socket.close
+      reset
+    end
 
-  # http://www.musicpd.org/doc/protocol/ch01s04.html
-  def command_list_ok_begin
-    raise "Already in command list" unless @command_list.nil?
-    write_command('command_list_ok_begin')
-    @command_list = []
-  end
+    def reset
+      @mpd_version = nil
+      @command_list = nil
+      @socket = nil
+      @log = nil
+      @connected = false
+    end
+
+    def connected?
+      @connected
+    end
 
-  def command_list_end
-    raise "Not in command list" if @command_list.nil?
-    write_command('command_list_end')
+    # http://www.musicpd.org/doc/protocol/ch01s04.html
+    def command_list_ok_begin
+      raise 'Already in command list' unless @command_list.nil?
+      write_command('command_list_ok_begin')
+      @command_list = []
+    end
 
-    return fetch_command_list
-  end
+    def command_list_end
+      raise 'Not in command list' if @command_list.nil?
+      write_command('command_list_end')
 
-  # The current logger. If no logger has been set MPDClient.log is used
-  #
-  def log
-    @log || MPDClient.log
-  end
+      fetch_command_list
+    end
 
-  # Sets the +logger+ used by this instance of MPDClient
-  #
-  def log= logger
-    @log = logger
-  end
+    # The current logger. If no logger has been set MPD::Client.log is used
+    def log
+      @log || MPD::Client.log
+    end
 
-  private
+    # Sets the +logger+ used by this instance of MPD::Client
+    attr_writer :log
 
-  def execute(command, *args, retval)
-    @mutex.synchronize do
-      if !@command_list.nil?
-        write_command(command, *args)
-        @command_list << retval
-      else
+    private
+
+    def ensure_connected
+      raise 'Please connect to MPD server' unless connected?
+    end
+
+    def execute(command, *args, retval)
+      @mutex.synchronize do
         write_command(command, *args)
-        eval retval
+
+        if !@command_list.nil?
+          @command_list << retval
+        else
+          eval retval
+        end
       end
     end
-  end
 
-  def write_line(line)
-    begin
-      @socket.puts line
-    rescue Errno::EPIPE
-      reconnect
-      @socket.puts line
+    def write_line(line)
+      begin
+        @socket.puts line
+      rescue Errno::EPIPE
+        reconnect
+        @socket.puts line
+      end
+      @socket.flush
     end
-    @socket.flush
-  end
 
-  def write_command(command, *args)
-    parts = [command]
-    args.each do |arg|
-      if arg.kind_of?(Array)
-        parts << (arg.size == 1 ? "\"#{arg[0].to_i}:\"" : "\"#{arg[0].to_i}:#{arg[1].to_i}\"")
-      else
-        parts << "\"#{escape(arg)}\""
+    def write_command(command, *args)
+      parts = [command]
+      args.each do |arg|
+        line = if arg.is_a?(Array)
+                 arg.size == 1 ? "\"#{arg[0].to_i}:\"" : "\"#{arg[0].to_i}:#{arg[1].to_i}\""
+               else
+                 "\"#{escape(arg)}\""
+               end
+
+        parts << line
       end
+      # log.debug("Calling MPD: #{command}#{args}") if log
+      log&.debug("Calling MPD: #{parts.join(' ')}")
+      write_line(parts.join(' '))
     end
-    #log.debug("Calling MPD: #{command}#{args}") if log
-    log.debug("Calling MPD: #{parts.join(' ')}") if log
-    write_line(parts.join(' '))
-  end
 
-  def read_line
-    line = @socket.gets.force_encoding('utf-8')
-    raise "Connection lost while reading line" unless line.end_with?("\n")
-    line.chomp!
-    if line.start_with?(ERROR_PREFIX)
-      error = line[/#{ERROR_PREFIX}(.*)/, 1].strip
-      raise error
-    end
+    def read_line
+      line = @socket.gets.force_encoding('utf-8')
+      raise 'Connection lost while reading line' unless line.end_with?("\n")
+      line.chomp!
+      if line.start_with?(ERROR_PREFIX)
+        error = line[/#{ERROR_PREFIX}(.*)/, 1].strip
+        raise error
+      end
 
-    if !@command_list.nil?
-      return if line == NEXT
-      raise "Got unexpected '#{SUCCESS}'" if line == SUCCESS
-    elsif line == SUCCESS
-      return
-    end
+      if !@command_list.nil?
+        return if line == NEXT
+        raise "Got unexpected '#{SUCCESS}'" if line == SUCCESS
+      elsif line == SUCCESS
+        return
+      end
 
-    return line
-  end
+      line
+    end
 
-  def read_pair(separator)
-    line = read_line
-    return if line.nil?
-    pair = line.split(separator, 2)
-    raise "Could now parse pair: '#{line}'" if pair.size < 2
+    def read_pair(separator)
+      line = read_line
+      return if line.nil?
+      pair = line.split(separator, 2)
+      raise "Could now parse pair: '#{line}'" if pair.size < 2
 
-    return pair #Array
-  end
+      pair # Array
+    end
 
-  def read_pairs(separator = ': ')
-    result = []
-    pair = read_pair(separator)
-    while pair
-      result << pair
+    def read_pairs(separator = ': ')
+      result = []
       pair = read_pair(separator)
-    end
+      while pair
+        result << pair
+        pair = read_pair(separator)
+      end
 
-    return result
-  end
+      result
+    end
 
-  def fetch_item
-    pairs = read_pairs
-    return nil if pairs.size != 1
-    return pairs[0][1]
-  end
+    def fetch_item
+      pairs = read_pairs
+      return nil if pairs.size != 1
 
-  def fetch_nothing
-    line = read_line
-    raise "Got unexpected return value: #{line}" unless line.nil?
-  end
+      pairs[0][1]
+    end
 
-  def fetch_list
-    result = []
-    seen = nil
-    read_pairs.each do |key, value|
-      if key != seen
-        if seen != nil
-          raise "Expected key '#{seen}', got '#{key}'"
-        end
-        seen = key
-      end
-      result << value
+    def fetch_nothing
+      line = read_line
+      raise "Got unexpected value: #{line}" unless line.nil?
     end
 
-    return result
-  end
+    def fetch_list
+      result = []
+      seen = nil
 
-  def fetch_objects(delimeters = [])
-    result = []
-    obj = {}
-    read_pairs.each do |key, value|
-      key = key.downcase
-      if delimeters.include?(key)
-        result << obj unless obj.empty?
-        obj = {}
-      elsif obj.include?(key)
-        obj[key] << value
+      read_pairs.each do |key, value|
+        if key != seen
+          raise "Expected key '#{seen}', got '#{key}'" unless seen.nil?
+          seen = key
+        end
+
+        result << value
       end
-      obj[key] = value
-    end
 
-    result << obj unless obj.empty?
+      result
+    end
 
-    return result
-  end
+    def fetch_objects(delimeters = [])
+      result = []
+      obj = {}
+      read_pairs.each do |key, value|
+        key = key.downcase
+        if delimeters.include?(key)
+          result << obj unless obj.empty?
+          obj = {}
+        elsif obj.include?(key)
+          obj[key] << value
+        end
+        obj[key] = value
+      end
 
-  def fetch_object
-    objs = fetch_objects
-    return objs ? objs[0] : {}
-  end
+      result << obj unless obj.empty?
 
-  def fetch_changes; fetch_objects(['cpos']); end
+      result
+    end
 
-  def fetch_songs; fetch_objects(['file']); end
+    def fetch_object
+      objs = fetch_objects
 
-  def fetch_mounts; fetch_objects(['mount']); end
+      objs ? objs[0] : {}
+    end
 
-  def fetch_neighbors; fetch_objects(['neighbor']); end
+    def fetch_changes
+      fetch_objects(['cpos'])
+    end
 
-  def fetch_messages; fetch_objects('channel'); end
+    def fetch_songs
+      fetch_objects(['file'])
+    end
 
-  def fetch_outputs; fetch_objects(['outputid']); end
+    def fetch_mounts
+      fetch_objects(['mount'])
+    end
 
-  def fetch_plugins; fetch_objects(['plugin']); end
+    def fetch_neighbors
+      fetch_objects(['neighbor'])
+    end
 
-  def fetch_database; fetch_objects(['file', 'directory', 'playlist']); end
+    def fetch_messages
+      fetch_objects('channel')
+    end
 
-  def fetch_playlists; fetch_objects(['playlist']); end
+    def fetch_outputs
+      fetch_objects(['outputid'])
+    end
 
-  def fetch_playlist
-    result = []
-    read_pairs(':').each do |key, value|
-      result << value
+    def fetch_plugins
+      fetch_objects(['plugin'])
     end
 
-    return result
-  end
+    def fetch_database
+      fetch_objects(%w[file directory playlist])
+    end
 
-  def fetch_stickers
-    result = []
-    read_pairs.each do |key, sticker|
-      value = sticker.split('=', 2)
-      raise "Could now parse sticker: #{sticker}" if value.size < 2
-      result << Hash[*value]
+    def fetch_playlists
+      fetch_objects(['playlist'])
     end
 
-    return result
-  end
+    def fetch_playlist
+      result = []
+      read_pairs(':').each do |_key, value|
+        result << value
+      end
 
-  def fetch_sticker; fetch_stickers[0]; end
+      result
+    end
 
-  def fetch_command_list
-    result = []
-    begin
-      @command_list.each do |retval|
-        result << (eval retval)
+    def fetch_stickers
+      result = []
+      read_pairs.each do |_key, sticker|
+        value = sticker.split('=', 2)
+        raise "Could now parse sticker: #{sticker}" if value.size < 2
+        result << Hash[*value]
       end
-    ensure
-      @command_list = nil
+
+      result
     end
 
-    return result
-  end
+    def fetch_sticker
+      fetch_stickers[0]
+    end
 
+    def fetch_command_list
+      result = []
+      begin
+        @command_list.each do |retval|
+          result << (eval retval)
+        end
+      ensure
+        @command_list = nil
+      end
 
-  def hello
-    line = @socket.gets
-    raise "Connection lost while reading MPD hello" unless line.end_with?("\n")
-    line.chomp!
-    raise "Got invalid MPD hello: #{line}" unless line.start_with?(HELLO_PREFIX)
-    @mpd_version = line[/#{HELLO_PREFIX}(.*)/, 1]
-  end
+      result
+    end
 
-  def reset
-    @mpd_version = nil
-    @command_list = nil
-    @socket = nil
-    @log = nil
-  end
+    def hello
+      line = @socket.gets
+      raise 'Connection lost while reading MPD hello' unless line.end_with?("\n")
+      line.chomp!
+      raise "Got invalid MPD hello: #{line}" unless line.start_with?(HELLO_PREFIX)
+      @mpd_version = line[/#{HELLO_PREFIX}(.*)/, 1]
+    end
 
-  def escape(text)
-    text.to_s.gsub("\\", "\\\\").gsub('"', '\\"')
+    def escape(text)
+      text.to_s.gsub('\\', '\\\\').gsub('"', '\\"')
+    end
   end
-
 end
 
-COMMANDS.each_pair do |name, callback|
-  MPDClient.add_command(name, callback)
+MPD::COMMANDS.each_pair do |name, callback|
+  MPD::Client.add_command(name, callback)
 end
-
diff --git a/lib/mpd_client/version.rb b/lib/mpd_client/version.rb
index 35bdda8..5656547 100644
--- a/lib/mpd_client/version.rb
+++ b/lib/mpd_client/version.rb
@@ -1,3 +1,7 @@
-class MPDClient
-  VERSION = "0.0.6"
+# frozen_string_literal: true
+
+module MPD
+  class Client
+    VERSION = '0.1.0'
+  end
 end
diff --git a/mpd_client.gemspec b/mpd_client.gemspec
index 5f0683f..3e03234 100644
--- a/mpd_client.gemspec
+++ b/mpd_client.gemspec
@@ -1,16 +1,22 @@
-require File.expand_path('../lib/mpd_client/version', __FILE__)
+# frozen_string_literal: true
+
+lib = File.expand_path('lib', __dir__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+require 'mpd_client/version'
 
 Gem::Specification.new do |gem|
-  gem.authors       = ["Anton Maminov"]
-  gem.email         = ["anton.linux@gmail.com"]
-  gem.description   = %q{Yet another Ruby MPD client library}
-  gem.summary       = %q{Simple Music Player Daemon library written entirely in Ruby}
-  gem.homepage      = "https://github.com/mamantoha/mpd_client"
+  gem.authors       = ['Anton Maminov']
+  gem.email         = ['anton.linux@gmail.com']
+  gem.description   = 'Yet another Ruby MPD client library'
+  gem.summary       = 'Simple Music Player Daemon library written entirely in Ruby'
+  gem.homepage      = 'https://github.com/mamantoha/mpd_client'
 
-  gem.files         = `git ls-files`.split($\)
-  gem.executables   = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
+  gem.files         = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
+  gem.executables   = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
   gem.test_files    = gem.files.grep(%r{^(test|spec|features)/})
-  gem.name          = "mpd_client"
-  gem.require_paths = ["lib"]
-  gem.version       = MPDClient::VERSION
+  gem.name          = 'mpd_client'
+  gem.require_paths = ['lib']
+  gem.version       = MPD::Client::VERSION
+
+  gem.add_development_dependency 'bundler', '~> 1.16'
 end
diff --git a/spec/mpd_client/mpd_client_spec.rb b/spec/mpd_client/mpd_client_spec.rb
new file mode 100644
index 0000000..7e9331d
--- /dev/null
+++ b/spec/mpd_client/mpd_client_spec.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe MPD::Client do
+  it 'should have version' do
+    expect(MPD::Client::VERSION).to_not be_nil
+  end
+
+  describe '#initialize' do
+    it 'should create new client' do
+      client = MPD::Client.new
+
+      expect(client.connected?).to eq(false)
+    end
+  end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000..d573127
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+$LOAD_PATH.unshift File.expand_path(__dir__)
+$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
+
+require 'mpd_client'
+require 'rspec'
+require 'pry'