Module: Songle::SongURI
- Included in:
- Mp3SongURI, NnSchemeSongURI, NnShortSongURI, NnSongURI, NumericSongURI, ScSchemeSongURI, ScSongURI, YtSchemeSongURI, YtShortSongURI, YtSongURI
- Defined in:
- lib/songle/song_uri.rb,
lib/songle/song_uri/nn_song_uri.rb,
lib/songle/song_uri/sc_song_uri.rb,
lib/songle/song_uri/yt_song_uri.rb,
lib/songle/song_uri/mp3_song_uri.rb,
lib/songle/song_uri/numeric_song_uri.rb,
lib/songle/song_uri/nn_short_song_uri.rb,
lib/songle/song_uri/yt_short_song_uri.rb,
lib/songle/song_uri/nn_scheme_song_uri.rb,
lib/songle/song_uri/sc_scheme_song_uri.rb,
lib/songle/song_uri/yt_scheme_song_uri.rb,
lib/songle/song_uri/invalid_song_uri_error.rb
Defined Under Namespace
Classes: InvalidSongURIError, Mp3SongURI, NnSchemeSongURI, NnShortSongURI, NnSongURI, NumericSongURI, ScSchemeSongURI, ScSongURI, YtSchemeSongURI, YtShortSongURI, YtSongURI
Constant Summary collapse
- ENDPOINT_SCHEME =
"https"- ENDPOINT_HOST =
"songle.jp"- ENDPOINT_PATH =
"/songs/"
Instance Attribute Summary collapse
-
#endpoint_host ⇒ Object
readonly
Returns the value of attribute endpoint_host.
-
#endpoint_path ⇒ Object
readonly
Returns the value of attribute endpoint_path.
-
#endpoint_scheme ⇒ Object
readonly
Returns the value of attribute endpoint_scheme.
-
#source_host ⇒ Object
readonly
Returns the value of attribute source_host.
-
#source_id ⇒ Object
readonly
Returns the value of attribute source_id.
-
#source_path ⇒ Object
readonly
Returns the value of attribute source_path.
Class Method Summary collapse
Instance Method Summary collapse
- #endpoint ⇒ Object
- #initialize(options = nil) ⇒ Object
- #permalink ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
Instance Attribute Details
#endpoint_host ⇒ Object (readonly)
Returns the value of attribute endpoint_host.
6 7 8 |
# File 'lib/songle/song_uri.rb', line 6 def endpoint_host @endpoint_host end |
#endpoint_path ⇒ Object (readonly)
Returns the value of attribute endpoint_path.
7 8 9 |
# File 'lib/songle/song_uri.rb', line 7 def endpoint_path @endpoint_path end |
#endpoint_scheme ⇒ Object (readonly)
Returns the value of attribute endpoint_scheme.
5 6 7 |
# File 'lib/songle/song_uri.rb', line 5 def endpoint_scheme @endpoint_scheme end |
#source_host ⇒ Object (readonly)
Returns the value of attribute source_host.
8 9 10 |
# File 'lib/songle/song_uri.rb', line 8 def source_host @source_host end |
#source_id ⇒ Object (readonly)
Returns the value of attribute source_id.
10 11 12 |
# File 'lib/songle/song_uri.rb', line 10 def source_id @source_id end |
#source_path ⇒ Object (readonly)
Returns the value of attribute source_path.
9 10 11 |
# File 'lib/songle/song_uri.rb', line 9 def source_path @source_path end |
Class Method Details
.parse(query_string, options = nil) ⇒ Object
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 |
# File 'lib/songle/song_uri.rb', line 82 def parse query_string, = nil query_string = ::URI.decode_www_form_component(query_string.to_s).gsub(/[+\s]/, "%20") case when query_string =~ ::Songle::SongURI::NnSongURI::URI_REGEXP return ::Songle::SongURI::NnSongURI.new(query_string, ) when query_string =~ ::Songle::SongURI::NnSchemeSongURI::URI_REGEXP return ::Songle::SongURI::NnSchemeSongURI.new(query_string, ) when query_string =~ ::Songle::SongURI::NnShortSongURI::URI_REGEXP return ::Songle::SongURI::NnShortSongURI.new(query_string, ) when query_string =~ ::Songle::SongURI::ScSongURI::URI_REGEXP return ::Songle::SongURI::ScSongURI.new(query_string, ) when query_string =~ ::Songle::SongURI::ScSchemeSongURI::URI_REGEXP return ::Songle::SongURI::ScSchemeSongURI.new(query_string, ) when query_string =~ ::Songle::SongURI::YtSongURI::URI_REGEXP return ::Songle::SongURI::YtSongURI.new(query_string, ) when query_string =~ ::Songle::SongURI::YtSchemeSongURI::URI_REGEXP return ::Songle::SongURI::YtSchemeSongURI.new(query_string, ) when query_string =~ ::Songle::SongURI::YtShortSongURI::URI_REGEXP return ::Songle::SongURI::YtShortSongURI.new(query_string, ) when query_string =~ ::Songle::SongURI::NumericSongURI::URI_REGEXP return ::Songle::SongURI::NumericSongURI.new(query_string, ) else return ::Songle::SongURI::Mp3SongURI.new(query_string, ) end end |
Instance Method Details
#endpoint ⇒ Object
46 47 48 |
# File 'lib/songle/song_uri.rb', line 46 def endpoint return "#{ self.endpoint_scheme }://#{ self.endpoint_host }#{ self.endpoint_path }" end |
#initialize(options = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/songle/song_uri.rb', line 30 def initialize = nil ||= {} @endpoint_scheme = ([ :endpoint_scheme ] || "").strip != "" ? [ :endpoint_scheme ].strip : ENDPOINT_SCHEME @endpoint_host = ([ :endpoint_host ] || "").strip != "" ? [ :endpoint_host ].strip : ENDPOINT_HOST @endpoint_path = ([ :endpoint_path ] || "").strip != "" ? [ :endpoint_path ].strip : ENDPOINT_PATH end |
#permalink ⇒ Object
53 54 55 |
# File 'lib/songle/song_uri.rb', line 53 def permalink return "http://#{ self.source_host }#{ self.source_path }" end |
#to_s ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/songle/song_uri.rb', line 67 def to_s encoded_source_host = ::URI.encode_www_form_component(self.source_host) encoded_source_path = ::URI.encode_www_form_component(self.source_path) return "#{ self.endpoint }#{ encoded_source_host }#{ encoded_source_path }" end |
#type ⇒ Object
60 61 62 |
# File 'lib/songle/song_uri.rb', line 60 def type return nil end |