Class: Fleakr::Objects::Url
- Inherits:
-
Object
- Object
- Fleakr::Objects::Url
- Defined in:
- lib/fleakr/objects/url.rb
Instance Method Summary collapse
- #collection? ⇒ Boolean
-
#initialize(url) ⇒ Url
constructor
A new instance of Url.
- #path ⇒ Object
- #resource ⇒ Object
- #resource_identifier ⇒ Object
- #resource_type ⇒ Object
- #shortened? ⇒ Boolean
- #user ⇒ Object
- #user_identifier ⇒ Object
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
40 41 42 |
# File 'lib/fleakr/objects/url.rb', line 40 def collection? resource_identifier.nil? end |
#path ⇒ Object
10 11 12 |
# File 'lib/fleakr/objects/url.rb', line 10 def path || original_path end |
#resource ⇒ Object
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_identifier ⇒ Object
22 23 24 |
# File 'lib/fleakr/objects/url.rb', line 22 def resource_identifier parts[3] end |
#resource_type ⇒ Object
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
18 19 20 |
# File 'lib/fleakr/objects/url.rb', line 18 def shortened? !original_path.match(%r{^/p/[123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ]+$}).nil? end |
#user ⇒ Object
26 27 28 |
# File 'lib/fleakr/objects/url.rb', line 26 def user @user ||= User.find_by_identifier(user_identifier) end |
#user_identifier ⇒ Object
14 15 16 |
# File 'lib/fleakr/objects/url.rb', line 14 def user_identifier (resource_type == Set) ? parts[1] : parts[2] end |