Class: Utils::ImageUrlFormatter
- Inherits:
-
Object
- Object
- Utils::ImageUrlFormatter
- Defined in:
- lib/link_oracle/Utils/image_url_formatter.rb
Instance Attribute Summary collapse
-
#image_url ⇒ Object
readonly
Returns the value of attribute image_url.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #encoded_image_url ⇒ Object
- #host ⇒ Object
- #host_missing? ⇒ Boolean
-
#initialize(url, image_url) ⇒ ImageUrlFormatter
constructor
A new instance of ImageUrlFormatter.
- #parsed_image_url ⇒ Object
- #parsed_url ⇒ Object
- #perform ⇒ Object
- #scheme ⇒ Object
- #scheme_missing? ⇒ Boolean
Constructor Details
#initialize(url, image_url) ⇒ ImageUrlFormatter
Returns a new instance of ImageUrlFormatter.
5 6 7 8 |
# File 'lib/link_oracle/Utils/image_url_formatter.rb', line 5 def initialize(url, image_url) @url = url @image_url = image_url end |
Instance Attribute Details
#image_url ⇒ Object (readonly)
Returns the value of attribute image_url.
3 4 5 |
# File 'lib/link_oracle/Utils/image_url_formatter.rb', line 3 def image_url @image_url end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/link_oracle/Utils/image_url_formatter.rb', line 3 def url @url end |
Instance Method Details
#encoded_image_url ⇒ Object
21 22 23 |
# File 'lib/link_oracle/Utils/image_url_formatter.rb', line 21 def encoded_image_url URI.encode(image_url) end |
#host ⇒ Object
25 26 27 |
# File 'lib/link_oracle/Utils/image_url_formatter.rb', line 25 def host parsed_url.host end |
#host_missing? ⇒ Boolean
45 46 47 |
# File 'lib/link_oracle/Utils/image_url_formatter.rb', line 45 def host_missing? !parsed_image_url.host end |
#parsed_image_url ⇒ Object
37 38 39 |
# File 'lib/link_oracle/Utils/image_url_formatter.rb', line 37 def parsed_image_url @parsed_image_url ||= URI.parse(encoded_image_url) end |
#parsed_url ⇒ Object
33 34 35 |
# File 'lib/link_oracle/Utils/image_url_formatter.rb', line 33 def parsed_url @parsed_url ||= URI.parse(url) end |
#perform ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/link_oracle/Utils/image_url_formatter.rb', line 10 def perform return unless image_url if host_missing? "#{scheme}://#{host}#{encoded_image_url}" elsif scheme_missing? "http:#{encoded_image_url}" else encoded_image_url end end |
#scheme ⇒ Object
29 30 31 |
# File 'lib/link_oracle/Utils/image_url_formatter.rb', line 29 def scheme parsed_url.scheme end |
#scheme_missing? ⇒ Boolean
41 42 43 |
# File 'lib/link_oracle/Utils/image_url_formatter.rb', line 41 def scheme_missing? parsed_image_url.scheme.to_s.empty? end |