Class: Sqed

Inherits:
Object
  • Object
show all
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, Extractor, Parser, Result

Constant Summary collapse

VERSION =
'0.5.2'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**opts) ⇒ Sqed

Returns a new instance of Sqed.



74
75
76
77
78
79
80
# File 'lib/sqed.rb', line 74

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.

Returns:

  • (Sqed::Boundaries instance)

    contains the coordinates of the internal stage sections



53
54
55
# File 'lib/sqed.rb', line 53

def boundaries
  @boundaries
end

#boundary_colorSymbol

describing the boundary color within the stage

Returns:

  • (Symbol)

    like ‘:red`, `:green`, `:blue`, defaults to `:green`



61
62
63
# File 'lib/sqed.rb', line 61

def boundary_color
  @boundary_color
end

#boundary_finderObject

Provide a boundary_finder, overrides metadata taken from pattern



72
73
74
# File 'lib/sqed.rb', line 72

def boundary_finder
  @boundary_finder
end

#has_borderBoolean

Returns defaults to ‘true` when true detects border on initialization.

Returns:

  • (Boolean)

    defaults to ‘true` when true detects border on initialization



57
58
59
# File 'lib/sqed.rb', line 57

def has_border
  @has_border
end

#imageObject

initial image which is an instance of ImageMagick::Image, containing background and stage, or just stage



25
26
27
# File 'lib/sqed.rb', line 25

def image
  @image
end

#layoutSymbol

!! Provide a specific layout, passed as option :layout, overrides layout metadata taken from :pattern, defaults to ‘:cross`

Returns:

  • (Symbol)

    like ‘:cross`



42
43
44
# File 'lib/sqed.rb', line 42

def layout
  @layout
end

#metadata_mapObject

Provide a metadata map, overrides metadata taken from pattern



69
70
71
# File 'lib/sqed.rb', line 69

def 
  @metadata_map
end

#patternSymbol

!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

Returns:

  • (Symbol)

    like ‘:seven_slot`, see Sqed::CONFIG for valid options,



38
39
40
# File 'lib/sqed.rb', line 38

def pattern
  @pattern
end

#stage_boundarySqed::Boundaries instance

Returns stores the coordinates of the stage.

Returns:



49
50
51
# File 'lib/sqed.rb', line 49

def stage_boundary
  @stage_boundary
end

#stage_imageObject

the image that is the cropped content for parsing



45
46
47
# File 'lib/sqed.rb', line 45

def stage_image
  @stage_image
end

#use_thumbnailBoolean

against a thumbnail version of the passed image

Returns:

  • (Boolean)

    defaults to ‘true` (faster, less accurate) if `true` do the boundary detection (not stage detection at present)



66
67
68
# File 'lib/sqed.rb', line 66

def use_thumbnail
  @use_thumbnail
end

Instance Method Details

#attributesHash

Returns an overview of data/metadata, for debugging purposes only.

Returns:

  • (Hash)

    an overview of data/metadata, for debugging purposes only



153
154
155
156
157
158
# File 'lib/sqed.rb', line 153

def attributes
  { image: image,
    boundaries: boundaries,
    stage_boundary: stage_boundary
  }.merge!()
end

#crop_imageImage

Returns crops the stage if not done, then sets/returns @stage_image.

Returns:

  • (Image)

    crops the stage if not done, then sets/returns @stage_image



130
131
132
133
134
135
136
137
# File 'lib/sqed.rb', line 130

def crop_image
  if has_border
    @stage_image = image.crop(*stage_boundary.for(SqedConfig.index_for_section_type(:stage, :stage)), true)
  else
    @stage_image = image
  end
  @stage_image
end

#extraction_metadataHash

Returns federate extraction options.

Returns:

  • (Hash)

    federate extraction options



84
85
86
87
88
89
90
91
92
93
# File 'lib/sqed.rb', line 84

def 
  {
      boundary_finder: boundary_finder,
      layout: layout,
      metadata_map: ,
      boundary_color: boundary_color,
      has_border: has_border,
      use_thumbnail: use_thumbnail
  }
end

#native_boundariesSqed::Boundaries instance?

Returns a boundaries instance that has the original image (prior to cropping stage) coordinates.

Returns:

  • (Sqed::Boundaries instance, nil)

    a boundaries instance that has the original image (prior to cropping stage) coordinates



120
121
122
123
124
125
126
# File 'lib/sqed.rb', line 120

def native_boundaries
  if @boundaries.complete
    @boundaries.offset(stage_boundary)
  else
    nil
  end
end

#resultObject



139
140
141
142
143
144
145
146
147
148
149
# File 'lib/sqed.rb', line 139

def result
  return false if image.nil?

  extractor = Sqed::Extractor.new(
    boundaries: boundaries,
    metadata_map: , #  extraction_metadata[:metadata_map],
    image: stage_image
  )

  extractor.result
end