lib/sqed/extractor.rb in sqed-0.1.9 vs lib/sqed/extractor.rb in sqed-0.2.0

- old
+ new

@@ -2,37 +2,43 @@ # An Extractor takes Boundries object and a metadata_map pattern and returns a Sqed::Result # class Sqed::Extractor + class Error < StandardError; end; + # a Sqed::Boundaries instance attr_accessor :boundaries # a metadata_map hash from EXTRACTION_PATTERNS like: # {0 => :annotated_specimen, 1 => :identifier, 2 =>:image_registration } attr_accessor :metadata_map # a Magick::Image file attr_accessor :image - def initialize(boundaries: boundaries, metadata_map: metadata_map, image: image) - raise 'boundaries not provided or provided boundary is not a Sqed::Boundaries' if boundaries.nil? || !boundaries.class == Sqed::Boundaries - raise 'metadata_map not provided or metadata_map not a Hash' if metadata_map.nil? || !metadata_map.class == Hash - raise 'image not provided' if image.nil? || !image.class.name == 'Magick::Image' + def initialize(target_boundaries: boundaries, target_metadata_map: metadata_map, target_image: image) + raise Error, 'boundaries not provided or provided boundary is not a Sqed::Boundaries' if target_boundaries.nil? || !target_boundaries.class == Sqed::Boundaries + raise Error, 'metadata_map not provided or metadata_map not a Hash' if target_metadata_map.nil? || !target_metadata_map.class == Hash + raise Error, 'image not provided' if target_image.nil? || !target_image.class.name == 'Magick::Image' - @metadata_map = metadata_map - @boundaries = boundaries - @image = image + @metadata_map = target_metadata_map + @boundaries = target_boundaries + @image = target_image end def result r = Sqed::Result.new() r.sections = metadata_map.values.sort # assign the images to the result boundaries.each do |section_index, coords| section_type = metadata_map[section_index] + + # TODO: raise this higher up the chain + raise Error, "invalid section_type [#{section_type}]" if !SqedConfig::LAYOUT_SECTION_TYPES.include?(section_type) + r.send("#{section_type}_image=", extract_image(coords)) r.boundary_coordinates[section_type] = coords end # assign the metadata to the result