Class: Fleakr::Objects::Url

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

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Url

Returns a new instance of Url.



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

def initialize(url)
  @url = url
end

Instance Method Details

#collection?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/fleakr/objects/url.rb', line 40

def collection?
  resource_identifier.nil?
end

#pathObject



10
11
12
# File 'lib/fleakr/objects/url.rb', line 10

def path
  expanded_path || original_path
end

#resourceObject



44
45
46
47
48
49
50
# File 'lib/fleakr/objects/url.rb', line 44

def resource
  if resource_type == User
    user
  else
    collection? ? resource_type.find_all_by_user_id(user.id) : resource_type.find_by_id(resource_identifier)
  end
end

#resource_identifierObject



22
23
24
# File 'lib/fleakr/objects/url.rb', line 22

def resource_identifier
  parts[3]
end

#resource_typeObject



30
31
32
33
34
35
36
37
38
# File 'lib/fleakr/objects/url.rb', line 30

def resource_type
  if parts[1] == 'people'
    User
  elsif parts[1] == 'photos'
    Photo
  elsif parts[2] == 'sets'
    Set
  end
end

#shortened?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/fleakr/objects/url.rb', line 18

def shortened?
  !original_path.match(%r{^/p/[123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ]+$}).nil?
end

#userObject



26
27
28
# File 'lib/fleakr/objects/url.rb', line 26

def user
  @user ||= User.find_by_identifier(user_identifier)
end

#user_identifierObject



14
15
16
# File 'lib/fleakr/objects/url.rb', line 14

def user_identifier
  (resource_type == Set) ? parts[1] : parts[2]
end