class Shibkit::MetaMeta::Logo
Class to represent technical or suppor contact details for an entity
Constants
- REQUIRED_QUACKS
- ROOT_ELEMENT
Element and attribute used to select XML for new objects
- TARGET_ATTR
Attributes
URI of the entity this logo is associated with
Height of the image as declared in XML
Language of the logo
URL of the image
URL of the image
Width of the image as declared in XML
Public Instance Methods
Logo
is within recommended size range?
# File lib/shibkit/meta_meta/logo.rb, line 147 def acceptable_size? return true if width > 50 and width < 100 and height > 50 and height < 100 end
Download the file and update this object based on real characteristics
# File lib/shibkit/meta_meta/logo.rb, line 181 def confirm_attribs? #begin width, height = Dimensions.dimensions(tmpfile.path) return pixels == metadata_pixels ? true : false #rescue return nil #end return true end
Download and cache the image, returning a filehandle
# File lib/shibkit/meta_meta/logo.rb, line 157 def download @tmpfile = fetch_remote(location) @fetched_at = Time.new return @tmpfile end
Returns number of pixels
# File lib/shibkit/meta_meta/logo.rb, line 89 def pixels return width.to_i * height.to_i end
PNG image? Convenience method since these are probably a better choice than JPEGs Not accurate…
# File lib/shibkit/meta_meta/logo.rb, line 117 def png? if @tmpfile begin image = ChunkyPNG::Image.from_file(@tmpfile.path) return true if image rescue return false end end return @png if @png return false if location.empty? # # ... return true if location =~ /[.]png$/ begin response = RestClient.head(location) return true if response.headers['content-type'] == 'image/png' rescue return false end return false end
Returns :square, :portrait or :landscape
# File lib/shibkit/meta_meta/logo.rb, line 96 def shape return :default if (75..85).include(width) and (55..65).include(height) return :square if width == height ## TODO: Needs a bit of tolerance for small differences return :portrait if height > width return :landscape if width > height ## Possibly running in the nightmare corpse-city of R'lyeh raise "Geometry of logo is abnormal, non-Euclidean, and loathsomely redolent of spheres and dimensions apart from ours." end
Calculated size of the image (:tiny :small :medium :large, etc) I’m not sure about these.
# File lib/shibkit/meta_meta/logo.rb, line 65 def size return case when pixels <= (16*16) :tiny when pixels <= (32*32) :small when pixels <= (64*64) :icon when pixels <= (4200..6200) :default when pixels <= (128*128) :medium when pixels <= (256*256) :large when pixels <= (512*512) :huge else :silly end end
HTTPS resource?
# File lib/shibkit/meta_meta/logo.rb, line 109 def ssl? return location =~ /^https/ ? true : false end
Filehandle for the local, downloaded file. Will download.
# File lib/shibkit/meta_meta/logo.rb, line 168 def tmpfile unless @tmpfile return download end return @tmpfile end
# File lib/shibkit/meta_meta/logo.rb, line 57 def to_s return location end
Private Instance Methods
Build the logo object from a suitable chunk of XML
# File lib/shibkit/meta_meta/logo.rb, line 199 def parse_xml if @noko and @noko.content self.location = @noko.content.to_s.strip || nil self.height = @noko['height'] ? @noko['height'].to_i : 0 self.width = @noko['width'] ? @noko['width'].to_i : 0 lang = @noko['xml:lang'] || :en @metadata_pixels = height * width log.debug " Derived logo #{url} from XML" end end