Class: RUtilAnts::URLCache::URLHandlers::DataImage
- Inherits:
-
Object
- Object
- RUtilAnts::URLCache::URLHandlers::DataImage
- Defined in:
- lib/rUtilAnts/URLHandlers/DataImage.rb
Overview
Handler of data:image URIs
Class Method Summary collapse
-
.getMatchingRegexps ⇒ Object
Get a list of regexps matching the URL to get to this handler.
Instance Method Summary collapse
-
#getContent(iFollowRedirections) ⇒ Object
Get the content of the URL.
-
#getCorrespondingFileBaseName ⇒ Object
Get a corresponding file base name.
-
#getCRC ⇒ Object
Get the current CRC of the URL.
-
#getServerID ⇒ Object
Get the server ID.
-
#initialize(iURL) ⇒ DataImage
constructor
Constructor.
Constructor Details
#initialize(iURL) ⇒ DataImage
Constructor
Parameters:
-
iURL (String): The URL that this handler will manage
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rUtilAnts/URLHandlers/DataImage.rb', line 29 def initialize(iURL) @URL = iURL lMatchData = @URL.match(/data:image\/(.*);base64,(.*)/) if (lMatchData == nil) logBug "URL #{iURL[0..23]}... was identified as a data:image like, but it appears to be false." else @Ext = lMatchData[1] if (@Ext == 'x-icon') @Ext = 'ico' end @Data = lMatchData[2] end end |
Class Method Details
.getMatchingRegexps ⇒ Object
Get a list of regexps matching the URL to get to this handler
Return:
-
list<Regexp>: The list of regexps matching URLs from this handler
19 20 21 22 23 |
# File 'lib/rUtilAnts/URLHandlers/DataImage.rb', line 19 def self.getMatchingRegexps return [ /^data:image.*$/ ] end |
Instance Method Details
#getContent(iFollowRedirections) ⇒ Object
Get the content of the URL
Parameters:
-
iFollowRedirections (Boolean): Do we follow redirections while accessing the content ?
Return:
-
Integer: Type of content returned
-
Object: The content, depending on the type previously returned:
** Exception if CONTENT_ERROR: The corresponding error ** String if CONTENT_REDIRECT: The new URL ** String if CONTENT_STRING: The real content ** String if CONTENT_LOCALFILENAME: The name of the local file name storing the content ** String if CONTENT_LOCALFILENAME_TEMPORARY: The name of the temporary local file name storing the content
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rUtilAnts/URLHandlers/DataImage.rb', line 82 def getContent(iFollowRedirections) rContentFormat = nil rContent = nil # Here we unpack the string in a base64 encoding. if (@Data.empty?) rContent = RuntimeError.new("Empty URI to decode: #{@URL}") rContentFormat = CONTENT_ERROR else rContent = @Data.unpack('m')[0] rContentFormat = CONTENT_STRING end return rContentFormat, rContent end |
#getCorrespondingFileBaseName ⇒ Object
Get a corresponding file base name. This method has to make sure file extensions are respected, as it can be used for further processing.
Return:
-
String: The file name
66 67 68 |
# File 'lib/rUtilAnts/URLHandlers/DataImage.rb', line 66 def getCorrespondingFileBaseName return "DataImage.#{@Ext}" end |
#getCRC ⇒ Object
Get the current CRC of the URL
Return:
-
Integer: The CRC
55 56 57 58 59 |
# File 'lib/rUtilAnts/URLHandlers/DataImage.rb', line 55 def getCRC # As the content is in the URL, it will be natural to not find it anymore in the cache when it is changed. # Therefore there is no need to return a CRC. return 0 end |
#getServerID ⇒ Object
Get the server ID
Return:
-
String: The server ID
47 48 49 |
# File 'lib/rUtilAnts/URLHandlers/DataImage.rb', line 47 def getServerID return nil end |