Class: Funky::URL

Inherits:
Object
  • Object
show all
Defined in:
lib/funky/url.rb

Constant Summary collapse

VIDEO_ID_REGEXES =
[/videos\/(\d+)(\/|)/i, /v=(\d*)/i, /\/v.\..*\/(\d*)\b/i]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ URL

Returns a new instance of URL.



6
7
8
# File 'lib/funky/url.rb', line 6

def initialize(url)
  @url = url
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/funky/url.rb', line 3

def url
  @url
end

Instance Method Details

#video_idObject



10
11
12
13
14
15
16
17
# File 'lib/funky/url.rb', line 10

def video_id
  return unless url.include? 'facebook.com'
  VIDEO_ID_REGEXES.each do |regex|
    url.match regex
    return $1 unless $1.nil? || $1.empty? || !$1.size.between?(15,17)
  end
  nil
end