Class: Loca::URL

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ URL



6
7
8
9
10
11
12
# File 'lib/loca/url.rb', line 6

def initialize(url)
  @url = url
  ensure_well_formed

  @branch_name = extract_branch_name
  @pr_num = extract_pr_num
end

Instance Attribute Details

#branch_nameObject (readonly)

Returns the value of attribute branch_name.



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

def branch_name
  @branch_name
end

#pr_numObject (readonly)

Returns the value of attribute pr_num.



4
5
6
# File 'lib/loca/url.rb', line 4

def pr_num
  @pr_num
end

Instance Method Details

#ensure_well_formedObject



18
19
20
21
22
23
24
25
# File 'lib/loca/url.rb', line 18

def ensure_well_formed
  # TODO: add more checks via Addressable::URI
  segments = URI(@url).path.split('/')
  int = Integer(segments[-1]) rescue false # replace with coercible gem?
  pull = segments[-2] == 'pull'

  fail Loca::Error::InvalidURL, "Doesn't appear to be a well-formed URL: #{@url}" unless int && pull
end

#to_sObject



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

def to_s
  @url
end