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

entity[RW]

URI of the entity this logo is associated with

height[RW]

Height of the image as declared in XML

language[RW]

Language of the logo

location[RW]

URL of the image

metadata_pixels[R]
url[RW]

URL of the image

width[RW]

Width of the image as declared in XML

Public Instance Methods

acceptable_size?() click to toggle source

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
confirm_attribs?() click to toggle source

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() click to toggle source

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
pixels() click to toggle source

Returns number of pixels

# File lib/shibkit/meta_meta/logo.rb, line 89
def pixels
  
  return width.to_i * height.to_i
  
end
png?() click to toggle source

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
shape() click to toggle source

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
size() click to toggle source

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
ssl?() click to toggle source

HTTPS resource?

# File lib/shibkit/meta_meta/logo.rb, line 109
def ssl?
  
  return location =~ /^https/ ? true : false
  
end
tmpfile() click to toggle source

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
to_s() click to toggle source
# File lib/shibkit/meta_meta/logo.rb, line 57
def to_s
  
  return location
  
end

Private Instance Methods

parse_xml() click to toggle source

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