Class: Sqed
- Inherits:
-
Object
- Object
- Sqed
- Defined in:
- lib/sqed.rb,
lib/sqed/result.rb,
lib/sqed/version.rb,
lib/sqed/extractor.rb,
lib/sqed/boundaries.rb,
lib/sqed/boundary_finder.rb
Overview
Instances take the following 1) An :image @image 2) A target extraction pattern, or individually specified attributes
Return a Sqed::Result
a = Sqed.new(pattern: :vertical_offset_cross, image: image)
b = a.result # => Sqed::Result instance
Defined Under Namespace
Classes: Boundaries, BoundaryFinder, Error, Extractor, Parser, Result
Constant Summary collapse
- VERSION =
'0.8.3'.freeze
Instance Attribute Summary collapse
-
#boundaries(force = false) ⇒ Sqed::Boundaries instance?
Contains the coordinates of the internal stage sections.
-
#boundary_color ⇒ Symbol
describing the boundary color within the stage.
-
#boundary_finder ⇒ Sqed::BoundaryFinder::<Klass>
Provide a boundary_finder, overrides metadata taken from pattern.
-
#has_border ⇒ Boolean
Defaults to ‘true` when true detects border on initialization.
-
#image ⇒ Object
initial image which is an instance of Magick::Image, containing background and stage, or just stage.
-
#layout ⇒ Symbol
!! Provide a specific layout, passed as option :layout, overrides layout metadata taken from :pattern, defaults to ‘:cross`.
-
#metadata_map ⇒ Object
Provide a metadata map, overrides metadata taken from pattern.
-
#pattern ⇒ Symbol
!optional! A lookup macro that if provided sets boundary_finder, layout, and metadata_map.
-
#stage_boundary ⇒ Sqed::Boundaries instance
!! Does not require ‘metadata_map` or `layout`.
-
#stage_image ⇒ Object
The image that is the cropped content for parsing !! Does not require ‘metadata_map` or `layout`.
-
#use_thumbnail ⇒ Boolean
against a thumbnail version of the passed image.
Instance Method Summary collapse
-
#crop_image ⇒ Image
Crops the stage if not done, then sets/returns @stage_image.
-
#extractable? ⇒ Boolean
‘true` if all boundary detection and image processing has been calculated with error.
-
#extraction_metadata ⇒ Hash
Federate extraction options.
-
#initialize(**opts) ⇒ Sqed
constructor
A new instance of Sqed.
- #result ⇒ Sqed::Result, false
Constructor Details
#initialize(**opts) ⇒ Sqed
Returns a new instance of Sqed.
80 81 82 83 84 85 86 |
# File 'lib/sqed.rb', line 80 def initialize(**opts) # extraction metadata @image = opts[:image] configure(opts) stub_results end |
Instance Attribute Details
#boundaries(force = false) ⇒ Sqed::Boundaries instance?
Returns Contains the coordinates of the internal stage sections. Calculates when set.
28 29 30 |
# File 'lib/sqed.rb', line 28 def boundaries @boundaries end |
#boundary_color ⇒ Symbol
describing the boundary color within the stage
32 33 34 |
# File 'lib/sqed.rb', line 32 def boundary_color @boundary_color end |
#boundary_finder ⇒ Sqed::BoundaryFinder::<Klass>
Provide a boundary_finder, overrides metadata taken from pattern
36 37 38 |
# File 'lib/sqed.rb', line 36 def boundary_finder @boundary_finder end |
#has_border ⇒ Boolean
Returns defaults to ‘true` when true detects border on initialization.
40 41 42 |
# File 'lib/sqed.rb', line 40 def has_border @has_border end |
#image ⇒ Object
initial image which is an instance of Magick::Image, containing background and stage, or just stage
43 44 45 |
# File 'lib/sqed.rb', line 43 def image @image end |
#layout ⇒ Symbol
!! Provide a specific layout, passed as option :layout, overrides layout metadata taken from :pattern, defaults to ‘:cross`
47 48 49 |
# File 'lib/sqed.rb', line 47 def layout @layout end |
#metadata_map ⇒ Object
Provide a metadata map, overrides metadata taken from pattern. No calculations are done here.
51 52 53 |
# File 'lib/sqed.rb', line 51 def @metadata_map end |
#pattern ⇒ Symbol
!optional! A lookup macro that if provided sets boundary_finder, layout, and metadata_map. These can be individually overwritten. Legal values are symbols taken from SqedConfig::EXTRACTION_PATTERNS.
!! Patterns are not intended to be persisted in external databases (they may change names). !! To persist Sqed metadata in something like Postgres reference individual attributes (e.g. layout, metadata_map, boundary_finder).
default value is ‘nil`
not required if layout, metadata_map, and boundary_finder are provided
64 65 66 |
# File 'lib/sqed.rb', line 64 def pattern @pattern end |
#stage_boundary ⇒ Sqed::Boundaries instance
!! Does not require ‘metadata_map` or `layout`
73 74 75 |
# File 'lib/sqed.rb', line 73 def stage_boundary @stage_boundary end |
#stage_image ⇒ Object
The image that is the cropped content for parsing !! Does not require ‘metadata_map` or `layout`
68 69 70 |
# File 'lib/sqed.rb', line 68 def stage_image @stage_image end |
#use_thumbnail ⇒ Boolean
against a thumbnail version of the passed image
78 79 80 |
# File 'lib/sqed.rb', line 78 def use_thumbnail @use_thumbnail end |
Instance Method Details
#crop_image ⇒ Image
Returns crops the stage if not done, then sets/returns @stage_image.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/sqed.rb', line 118 def crop_image begin if has_border && image @stage_image = image.crop(*stage_boundary.for(SqedConfig.index_for_section_type(:stage, :stage)), true) elsif image @stage_image = image end @stage_image rescue Sqed::Error raise rescue raise Sqed::Error, 'error cropping image' end end |
#extractable? ⇒ Boolean
Returns ‘true` if all boundary detection and image processing has been calculated with error.
159 160 161 |
# File 'lib/sqed.rb', line 159 def extractable? stage_image && && boundaries end |
#extraction_metadata ⇒ Hash
Returns federate extraction options.
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/sqed.rb', line 90 def { boundary_finder: boundary_finder, layout: layout, metadata_map: , boundary_color: boundary_color, has_border: has_border, use_thumbnail: use_thumbnail } end |
#result ⇒ Sqed::Result, false
164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/sqed.rb', line 164 def result return false unless extractable? extractor = Sqed::Extractor.new( boundaries: boundaries, metadata_map: , image: stage_image ) extractor.result end |