Class: Xmfun::Util::UrlParser

Inherits:
Object
  • Object
show all
Defined in:
lib/xmfun/util/url_parser.rb

Class Method Summary collapse

Class Method Details

.parse(url) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/xmfun/util/url_parser.rb', line 6

def self.parse(url)
  if uri? url
    url_array = url.split("//").last.split(/(\/|\?)/)
    type, id = url_array[2], url_array[4]

    case type
     when "album"   then "http://www.xiami.com/song/playlist/id/#{id}/type/1"
     when "artist"  then "http://www.xiami.com/song/playlist/id/#{id}/type/2"
     when "collect" then "http://www.xiami.com/song/playlist/id/#{id}/type/3"
     when "song"    then "http://www.xiami.com/song/playlist/id/#{id}/object_name/default/object_id/0"
     else ""
    end
  else
   false
  end
end

.uri?(uri) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/xmfun/util/url_parser.rb', line 23

def self.uri?(uri)
  uri =~ /\A#{URI::regexp(['http', 'https'])}\z/
end