Class: Shibkit::MetaMeta::Logo

Inherits:
MetadataItem show all
Includes:
Mixin::CachedDownloads
Defined in:
lib/shibkit/meta_meta/logo.rb

Overview

Class to represent technical or suppor contact details for an entity

Constant Summary collapse

ROOT_ELEMENT =

Element and attribute used to select XML for new objects

'Logo'
TARGET_ATTR =
'width'
REQUIRED_QUACKS =
[:location]

Constants inherited from MetadataItem

MetadataItem::NAMESPACES

Instance Attribute Summary collapse

Attributes inherited from MetadataItem

#read_at

Instance Method Summary collapse

Methods included from Mixin::CachedDownloads

#fetch_local, #fetch_remote, included

Methods inherited from MetadataItem

#filter, #from_xml, #hashed_id, #initialize, #parsed_xml, #purge_xml, #source_xml, #textify_xml, #to_hash, #to_rdf, #to_xml

Constructor Details

This class inherits a constructor from Shibkit::MetaMeta::MetadataItem

Instance Attribute Details

#entityObject

URI of the entity this logo is associated with



39
40
41
# File 'lib/shibkit/meta_meta/logo.rb', line 39

def entity
  @entity
end

#heightObject

Height of the image as declared in XML



42
43
44
# File 'lib/shibkit/meta_meta/logo.rb', line 42

def height
  @height
end

#languageObject

Language of the logo



53
54
55
# File 'lib/shibkit/meta_meta/logo.rb', line 53

def language
  @language
end

#locationObject Also known as: url

URL of the image



48
49
50
# File 'lib/shibkit/meta_meta/logo.rb', line 48

def location
  @location
end

#metadata_pixelsObject (readonly)

Returns the value of attribute metadata_pixels.



55
56
57
# File 'lib/shibkit/meta_meta/logo.rb', line 55

def 
  @metadata_pixels
end

#widthObject

Width of the image as declared in XML



45
46
47
# File 'lib/shibkit/meta_meta/logo.rb', line 45

def width
  @width
end

Instance Method Details

#acceptable_size?Boolean

Logo is within recommended size range?

Returns:

  • (Boolean)


147
148
149
150
151
152
153
154
# 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?Boolean

Download the file and update this object based on real characteristics

Returns:

  • (Boolean)


181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/shibkit/meta_meta/logo.rb', line 181

def confirm_attribs?

  #begin
    
    width, height = Dimensions.dimensions(tmpfile.path)  
    return pixels ==  ? true : false 
      
  #rescue
    return nil   
  #end
    
  return true
 
end

#downloadObject

Download and cache the image, returning a filehandle



157
158
159
160
161
162
163
164
165
# File 'lib/shibkit/meta_meta/logo.rb', line 157

def download

  @tmpfile = fetch_remote(location)
   
  @fetched_at = Time.new
   
  return @tmpfile
  
end

#pixelsObject

Returns number of pixels



89
90
91
92
93
# File 'lib/shibkit/meta_meta/logo.rb', line 89

def pixels
  
  return width.to_i * height.to_i
  
end

#png?Boolean

PNG image? Convenience method since these are probably a better choice than JPEGs Not accurate…

Returns:

  • (Boolean)


117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# 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

#shapeObject

Returns :square, :portrait or :landscape



96
97
98
99
100
101
102
103
104
105
106
# 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

#sizeObject

Calculated size of the image (:tiny :small :medium :large, etc) I’m not sure about these.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# 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?Boolean

HTTPS resource?

Returns:

  • (Boolean)


109
110
111
112
113
# File 'lib/shibkit/meta_meta/logo.rb', line 109

def ssl?
  
  return location =~ /^https/ ? true : false
  
end

#tmpfileObject

Filehandle for the local, downloaded file. Will download.



168
169
170
171
172
173
174
175
176
177
178
# File 'lib/shibkit/meta_meta/logo.rb', line 168

def tmpfile

  unless @tmpfile
    
    return download
    
  end
  
  return @tmpfile

end

#to_sObject



57
58
59
60
61
# File 'lib/shibkit/meta_meta/logo.rb', line 57

def to_s
  
  return location
  
end