Class: Loca::URL
- Inherits:
-
Object
- Object
- Loca::URL
- Defined in:
- lib/loca/url.rb
Instance Attribute Summary collapse
-
#branch_name ⇒ Object
readonly
Returns the value of attribute branch_name.
-
#pr_num ⇒ Object
readonly
Returns the value of attribute pr_num.
Instance Method Summary collapse
- #ensure_well_formed ⇒ Object
-
#initialize(url) ⇒ URL
constructor
A new instance of URL.
- #to_s ⇒ Object
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_name ⇒ Object (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_num ⇒ Object (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_formed ⇒ Object
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_s ⇒ Object
14 15 16 |
# File 'lib/loca/url.rb', line 14 def to_s @url end |