import 'package:funkblubber/funkentity.dart'; import 'package:funkblubber/console.dart' as console; FunkObject extract(final List args) { FunkObject result = FunkObject( kind: FunkEntity.error, id: '', domain: '', ); if (args.isEmpty) { console.error('no arguments provided'); return result; } try { final Uri uri = Uri.parse(args[0]); final segments = uri.pathSegments; for (int i = 0; i < segments.length; ++i) { switch (segments[i]) { case 'artists': result = FunkObject( kind: FunkEntity.artist, id: segments[i + 1], domain: uri.host, ); ++i; break; case 'albums': result = FunkObject( kind: FunkEntity.album, id: segments[i + 1], domain: uri.host, ); ++i; break; } } } catch (e) { console.error(e.toString()); result = FunkObject( kind: FunkEntity.error, id: '', domain: '', ); } return result; }