Class: TrailerVote::MediaTypes::Types::FormattedUrl
- Inherits:
-
Object
- Object
- TrailerVote::MediaTypes::Types::FormattedUrl
- Defined in:
- lib/trailer_vote/media_types/types/formatted_url.rb
Defined Under Namespace
Classes: UnexpectedFormatVariable
Instance Method Summary collapse
- #===(other) ⇒ Object
-
#initialize(*variables) ⇒ FormattedUrl
constructor
A new instance of FormattedUrl.
Constructor Details
#initialize(*variables) ⇒ FormattedUrl
Returns a new instance of FormattedUrl.
29 30 31 32 33 34 35 36 |
# File 'lib/trailer_vote/media_types/types/formatted_url.rb', line 29 def initialize(*variables) @variables = variables.map { |variable| "{#{variable}}" } = @variables.map { |variable| Regexp.escape(variable) } sections_first = "(?>#{.push('[^\s\/$.?#\{\}]').join('|')})" sections_not_first = "(?>#{.push('[^\\s\\{\\}]').join('|')})" @test = %r{^https?:\/\/#{sections_first}#{sections_not_first}*$} end |
Instance Method Details
#===(other) ⇒ Object
38 39 40 41 |
# File 'lib/trailer_vote/media_types/types/formatted_url.rb', line 38 def ===(other) return true if @test.match?(other) raise UnexpectedFormatVariable.new(variables: @variables, actual: other) end |