Class: Songle::SongURI::Mp3SongURI

Inherits:
Object
  • Object
show all
Includes:
Songle::SongURI
Defined in:
lib/songle/song_uri/mp3_song_uri.rb

Constant Summary collapse

TYPE =
"mp3"
URI_REGEXP =
/^(\/\/|http(|s):\/\/)(.+)$/

Constants included from Songle::SongURI

ENDPOINT_HOST, ENDPOINT_PATH, ENDPOINT_SCHEME

Instance Attribute Summary

Attributes included from Songle::SongURI

#endpoint_host, #endpoint_path, #endpoint_scheme, #source_host, #source_id, #source_path

Instance Method Summary collapse

Methods included from Songle::SongURI

#endpoint, parse, #permalink

Constructor Details

#initialize(query_string, options) ⇒ Mp3SongURI

Returns a new instance of Mp3SongURI.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/songle/song_uri/mp3_song_uri.rb', line 18

def initialize query_string, options
  super(options)

  if query_string =~ URI_REGEXP
    query_string = $3
  end

  if query_string =~ /#{ self.endpoint_host }#{ self.endpoint_path }(.+)/
    query_string = $1
  end

  source_uri =
    ::URI.parse("//#{ query_string }")

  @source_host = source_uri.host
  @source_path = source_uri.path + (!!source_uri.query ? "?#{ source_uri.query }" : "")
  @source_id   = nil
end

Instance Method Details

#to_sObject



47
48
49
50
51
52
53
54
55
# File 'lib/songle/song_uri/mp3_song_uri.rb', line 47

def to_s
  encoded_source_host =
    ::URI.encode_www_form_component(self.source_host).gsub(/[+\s]/, "%2520")

  encoded_source_path =
    ::URI.encode_www_form_component(self.source_path).gsub(/[+\s]/, "%2520")

  return "#{ self.endpoint }#{ encoded_source_host }#{ encoded_source_path }"
end

#typeObject



40
41
42
# File 'lib/songle/song_uri/mp3_song_uri.rb', line 40

def type
  return TYPE
end