-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathrequest_path.rb
More file actions
49 lines (41 loc) · 942 Bytes
/
request_path.rb
File metadata and controls
49 lines (41 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true
module Html2rss
module Web
##
# Provides helper methods to get config names by the request path.
class RequestPath
attr_reader :folder_name
##
# @param request [Rack::Request, #path]
def initialize(request)
@full_path = request.path[1..]
parts = @full_path.split('/')
if parts.size == 1
@name_with_ext = @full_path
else
@folder_name = parts[0..-2]
@name_with_ext = parts[-1]
end
end
##
# @return [String]
def full_config_name
[@folder_name, config_name].compact.join('/')
end
##
# @return [String]
def config_name
parts[..-2].join('.')
end
##
# @return [String]
def extension
parts.last
end
private
def parts
@parts ||= @name_with_ext.split('.')
end
end
end
end