Class: Applitools::Selenium::VGResource
- Inherits:
-
Object
- Object
- Applitools::Selenium::VGResource
- Includes:
- Jsonable
- Defined in:
- lib/applitools/selenium/visual_grid/vg_resource.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#handle_css_block ⇒ Object
Returns the value of attribute handle_css_block.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .parse_blob_from_script(blob, options = {}) ⇒ Object
- .parse_response(url, response, options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(url, content_type, content, options = {}) ⇒ VGResource
constructor
A new instance of VGResource.
- #lookup_for_resources ⇒ Object
- #on_css_fetched(block) ⇒ Object
- #stringify ⇒ Object
Constructor Details
#initialize(url, content_type, content, options = {}) ⇒ VGResource
Returns a new instance of VGResource.
24 25 26 27 28 29 30 31 32 |
# File 'lib/applitools/selenium/visual_grid/vg_resource.rb', line 24 def initialize(url, content_type, content, = {}) self.handle_css_block = [:on_css_fetched] if [:on_css_fetched].is_a? Proc self.url = URI(url) self.content_type = content_type self.content = content self.hash = Digest::SHA256.hexdigest(content) self.hashFormat = 'sha256' lookup_for_resources end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
8 9 10 |
# File 'lib/applitools/selenium/visual_grid/vg_resource.rb', line 8 def content @content end |
#handle_css_block ⇒ Object
Returns the value of attribute handle_css_block.
8 9 10 |
# File 'lib/applitools/selenium/visual_grid/vg_resource.rb', line 8 def handle_css_block @handle_css_block end |
#url ⇒ Object
Returns the value of attribute url.
8 9 10 |
# File 'lib/applitools/selenium/visual_grid/vg_resource.rb', line 8 def url @url end |
Class Method Details
.parse_blob_from_script(blob, options = {}) ⇒ Object
13 14 15 16 |
# File 'lib/applitools/selenium/visual_grid/vg_resource.rb', line 13 def parse_blob_from_script(blob, = {}) content = Base64.decode64(blob['value']) new(blob['url'], blob['type'], content, ) end |
.parse_response(url, response, options = {}) ⇒ Object
18 19 20 21 |
# File 'lib/applitools/selenium/visual_grid/vg_resource.rb', line 18 def parse_response(url, response, = {}) return new(url, 'application/empty-response', '') unless response.status == 200 new(url, response.headers['Content-Type'], response.body, ) end |
Instance Method Details
#lookup_for_resources ⇒ Object
38 39 40 41 42 43 |
# File 'lib/applitools/selenium/visual_grid/vg_resource.rb', line 38 def lookup_for_resources if %r{^text/css}i =~ content_type && handle_css_block parser = Applitools::Selenium::CssParser::FindEmbeddedResources.new(content) handle_css_block.call(parser.imported_css + parser.fonts + parser.images, url) end end |
#on_css_fetched(block) ⇒ Object
34 35 36 |
# File 'lib/applitools/selenium/visual_grid/vg_resource.rb', line 34 def on_css_fetched(block) self.handle_css_block = block end |
#stringify ⇒ Object
45 46 47 |
# File 'lib/applitools/selenium/visual_grid/vg_resource.rb', line 45 def stringify url.to_s + content_type.to_s + hash end |