Class: Fontist::Utils::GitHubUrl

Inherits:
Object
  • Object
show all
Defined in:
lib/fontist/utils/github_url.rb

Defined Under Namespace

Classes: ParsedUrl

Constant Summary collapse

GITHUB_RELEASE_PATTERN =
%r{^https?://github\.com/(?<owner>[^/]+)/(?<repo>[^/]+)/releases/download/(?<tag>[^/]+)/(?<asset>.+)$}.freeze

Class Method Summary collapse

Class Method Details

.match?(url) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/fontist/utils/github_url.rb', line 8

def match?(url)
  parse(url).matched?
end

.parse(url) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fontist/utils/github_url.rb', line 12

def parse(url)
  url_string = url.to_s
  match = url_string.match(GITHUB_RELEASE_PATTERN)

  if match
    ParsedUrl.new(
      owner: match[:owner],
      repo: match[:repo],
      tag: match[:tag],
      asset: match[:asset],
      original_url: url_string,
    )
  else
    ParsedUrl.from_non_github_url(url_string)
  end
end