Class: AVM::Image
- Inherits:
-
Object
- Object
- AVM::Image
- Defined in:
- lib/avm/image.rb
Overview
A single image, which has Observations, Contacts, and other metadata
Constant Summary collapse
- DUBLIN_CORE_FIELDS =
[ :title, :description ]
- PHOTOSHOP_SINGLE_FIELDS =
[ 'Headline', 'DateCreated', 'Credit' ]
- PHOTOSHOP_SINGLE_METHODS =
[ :headline, :date, :credit ]
- PHOTOSHOP_SINGLES_MESSAGES =
[ :headline, :string_date, :credit ]
- PHOTOSHOP_SINGLES_FOR_METHODS =
PHOTOSHOP_SINGLE_FIELDS.zip(PHOTOSHOP_SINGLE_METHODS)
- PHOTOSHOP_SINGLES_FOR_MESSAGES =
PHOTOSHOP_SINGLE_FIELDS.zip(PHOTOSHOP_SINGLES_MESSAGES)
- AVM_SINGLE_FIELDS =
[ 'Distance.Notes', 'Spectral.Notes', 'ReferenceURL', 'ID', 'Type', 'Image.ProductQuality', 'Spatial.Equinox', 'Spatial.Rotation', 'Spatial.Notes', 'Spatial.FITSheader', 'Spatial.Quality', 'Spatial.CoordsystemProjection', 'Spatial.CDMatrix', 'Spatial.Scale', 'Spatial.ReferencePixel', 'Spatial.ReferenceDimension', 'Spatial.ReferenceValue', 'Spatial.Equinox', 'Spatial.CoordinateFrame', 'Publisher', 'PublisherID', 'ResourceID', 'ResourceURL', 'RelatedResources', 'MetadataDate', 'MetadataVersion', 'Subject.Category', ]
- AVM_SINGLE_METHODS =
[ :distance_notes, :spectral_notes, :reference_url, :id, :type, :quality, :spatial_equinox, :spatial_rotation, :spatial_notes, :fits_header, :spatial_quality, :coordinate_system_projection, :spatial_cd_matrix, :spatial_scale, :reference_pixel, :reference_dimension, :reference_value, :equinox, :coordinate_frame, :publisher, :publisher_id, :resource_id, :resource_url, :related_resources, :metadata_date, :metadata_version, :categories ]
- AVM_SINGLE_MESSAGES =
[ :distance_notes, :spectral_notes, :reference_url, :id, :image_type, :image_quality, :spatial_equinox, :spatial_rotation, :spatial_notes, :fits_header, :spatial_quality, :coordinate_system_projection, :spatial_cd_matrix, :spatial_scale, :reference_pixel, :reference_dimension, :reference_value, :equinox, :coordinate_frame, :publisher, :publisher_id, :resource_id, :resource_url, :related_resources, :string_metadata_date, :metadata_version, :categories ]
- AVM_SINGLES =
AVM_SINGLE_FIELDS.zip(AVM_SINGLE_METHODS)
- AVM_SINGLES_FOR_MESSAGES =
AVM_SINGLE_FIELDS.zip(AVM_SINGLE_MESSAGES)
- AVM_TO_FLOAT =
[ :spatial_rotation, :spatial_cd_matrix, :spatial_scale, :reference_pixel, :reference_dimension, :reference_value ]
- HASH_FIELDS =
[ :title, :headline, :description, :distance_notes, :spectral_notes, :reference_url, :credit, :date, :id, :image_type, :image_quality, :coordinate_frame, :equinox, :reference_value, :reference_dimension, :reference_pixel, :spatial_scale, :spatial_rotation, :coordinate_system_projection, :spatial_quality, :spatial_notes, :fits_header, :spatial_cd_matrix, :distance, :publisher, :publisher_id, :resource_id, :resource_url, :related_resources, :metadata_date, :metadata_version, :subject_names, :categories ]
Instance Attribute Summary collapse
-
#creator ⇒ Object
readonly
Returns the value of attribute creator.
-
#observations ⇒ Object
readonly
Returns the value of attribute observations.
Class Method Summary collapse
Instance Method Summary collapse
- #coordinate_frame ⇒ Object
- #coordinate_system_projection ⇒ Object
- #create_observation(options) ⇒ Object
- #date ⇒ Object
- #distance ⇒ Object
- #id ⇒ Object
- #image_quality ⇒ Object
- #image_type ⇒ Object
-
#initialize(options = {}) ⇒ Image
constructor
A new instance of Image.
- #metadata_date ⇒ Object
- #method_missing(method) ⇒ Object
- #spatial_quality ⇒ Object
- #string_date ⇒ Object
- #string_metadata_date ⇒ Object
- #to_h ⇒ Object
- #to_xml ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Image
Returns a new instance of Image.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/avm/image.rb', line 150 def initialize( = {}) @creator = AVM::Creator.new(self) @options = AVM_TO_FLOAT.each do |field| @options[field] = case (value = @options[field]) when Array value.collect(&:to_f) else value ? value.to_f : nil end end @observations = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
329 330 331 |
# File 'lib/avm/image.rb', line 329 def method_missing(method) @options[method] end |
Instance Attribute Details
#creator ⇒ Object (readonly)
Returns the value of attribute creator.
148 149 150 |
# File 'lib/avm/image.rb', line 148 def creator @creator end |
#observations ⇒ Object (readonly)
Returns the value of attribute observations.
148 149 150 |
# File 'lib/avm/image.rb', line 148 def observations @observations end |
Class Method Details
.from_xml(string) ⇒ Object
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/avm/image.rb', line 265 def self.from_xml(string) document = AVM::XMP.from_string(string) = {} document.get_refs do |refs| DUBLIN_CORE_FIELDS.each do |field| if node = refs[:dublin_core].at_xpath(".//dc:#{field}//rdf:li[1]") [field] = node.text end end if node = refs[:dublin_core].at_xpath(".//dc:subject/rdf:Bag") [:subject_names] = node.search('./rdf:li').collect(&:text) end AVM_SINGLES.each do |tag, field| if node = refs[:avm].at_xpath("./avm:#{tag}") if field == :categories [field] = node.text.split(";").collect(&:strip) else if !(list_items = node.search('.//rdf:li')).empty? [field] = list_items.collect(&:text) else [field] = node.text end end end end PHOTOSHOP_SINGLES_FOR_METHODS.each do |tag, field| if node = refs[:photoshop].at_xpath("./photoshop:#{tag}") [field] = node.text end end if node = refs[:avm].at_xpath('./avm:Distance') list_values = node.search('.//rdf:li').collect { |li| li.text } case list_values.length when 0 [:light_years] = node.text when 1 [:light_years] = list_values.first when 2 [:light_years] = (list_values.first == '-') ? nil : list_values.first [:redshift] = list_values.last end end end image = new() image.creator.from_xml(self, document) Observation.from_xml(image, document) image end |
Instance Method Details
#coordinate_frame ⇒ Object
237 238 239 |
# File 'lib/avm/image.rb', line 237 def coordinate_frame cv_class_instance_for(AVM::CoordinateFrame, :coordinate_frame) end |
#coordinate_system_projection ⇒ Object
241 242 243 |
# File 'lib/avm/image.rb', line 241 def coordinate_system_projection cv_class_instance_for(AVM::CoordinateSystemProjection, :coordinate_system_projection) end |
#create_observation(options) ⇒ Object
171 172 173 174 175 |
# File 'lib/avm/image.rb', line 171 def create_observation() observation = Observation.new(self, ) @observations << observation observation end |
#date ⇒ Object
245 246 247 |
# File 'lib/avm/image.rb', line 245 def date date_or_nil(:date) end |
#distance ⇒ Object
261 262 263 |
# File 'lib/avm/image.rb', line 261 def distance [ light_years, redshift ] end |
#id ⇒ Object
221 222 223 |
# File 'lib/avm/image.rb', line 221 def id @options[:id] end |
#image_quality ⇒ Object
229 230 231 |
# File 'lib/avm/image.rb', line 229 def image_quality cv_class_instance_for(AVM::ImageQuality, :quality) end |
#image_type ⇒ Object
225 226 227 |
# File 'lib/avm/image.rb', line 225 def image_type cv_class_instance_for(AVM::ImageType, :type) end |
#metadata_date ⇒ Object
249 250 251 |
# File 'lib/avm/image.rb', line 249 def date_or_nil(:metadata_date) end |
#spatial_quality ⇒ Object
233 234 235 |
# File 'lib/avm/image.rb', line 233 def spatial_quality cv_class_instance_for(AVM::SpatialQuality, :spatial_quality) end |
#string_date ⇒ Object
253 254 255 |
# File 'lib/avm/image.rb', line 253 def string_date string_date_or_nil(:date) end |
#string_metadata_date ⇒ Object
257 258 259 |
# File 'lib/avm/image.rb', line 257 def string_date_or_nil(:metadata_date) end |
#to_h ⇒ Object
322 323 324 325 326 327 |
# File 'lib/avm/image.rb', line 322 def to_h hash = Hash[HASH_FIELDS.collect { |key| [ key, send(key) ] }] hash[:creator] = creator.to_a hash[:observations] = observations.collect(&:to_h) hash end |
#to_xml ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/avm/image.rb', line 177 def to_xml document = AVM::XMP.new creator.add_to_document(document) Observation.add_to_document(document, observations) document.get_refs do |refs| DUBLIN_CORE_FIELDS.each do |field| refs[:dublin_core].add_child(%{<dc:#{field}>#{alt_li_tag(send(field))}</dc:#{field}>}) end PHOTOSHOP_SINGLES_FOR_MESSAGES.each do |tag, | refs[:photoshop].add_child(%{<photoshop:#{tag}>#{send()}</photoshop:#{tag}>}) end AVM_SINGLES_FOR_MESSAGES.each do |tag, | if value = send() case value when Array container_tag = ( == :related_resources) ? 'Bag' : 'Seq' value = "<rdf:#{container_tag}>" + value.collect { |v| "<rdf:li>#{v.to_s}</rdf:li>" }.join + "</rdf:#{container_tag}>" else value = value.to_s end refs[:avm].add_child(%{<avm:#{tag}>#{value}</avm:#{tag}>}) end end distance_nodes = [] distance_nodes << rdf_li(light_years) if light_years if redshift distance_nodes << rdf_li('-') if distance_nodes.empty? distance_nodes << rdf_li(redshift) end if !distance_nodes.empty? refs[:avm].add_child(%{<avm:Distance><rdf:Seq>#{distance_nodes.join}</rdf:Seq></avm:Distance>}) end end document.doc end |
#valid? ⇒ Boolean
167 168 169 |
# File 'lib/avm/image.rb', line 167 def valid? self.title && self.credit end |