sqed 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a06556fe8ccfebadb944693c4c8675f2ae95e019
4
- data.tar.gz: 72aa2b8778bfb884b9cb524db4287c18d3641ccb
3
+ metadata.gz: a75cdb9451a36a8aec4846d4fc9af3809ae8b6a6
4
+ data.tar.gz: 8a02cda6c7e44a7942b7ab5cefaf045c38ca6b99
5
5
  SHA512:
6
- metadata.gz: b6df4ecaa35e16585fcc03c2fe05bfcd610b25ae92c5dfb3715d4f9cc4f9d930af3fe4f0f18d61318a683d30629a70f459cc233c4860b3c5e91d3b59825c871b
7
- data.tar.gz: ad2d4dd2f09a43994ae6add3f5c45d72004ac8d141b820d32909cf1a72b13fbedc8628aa178311516c39bb099c3c690bd3c248c06e8697294f4136e40496dd3d
6
+ metadata.gz: e3194e5fc9e13f1c04e652df9aeb614315da25106a8173e602ac88df8fe23516d5ab38ebbfdf151ef9f43a6d29ff97b249b01c87b40d962ff0c13a7f9bf1d33e
7
+ data.tar.gz: d7e34abf58f07cf8e19c5175ade4eecf2528675180350fc9a7b1ad2d3c01bf9d828c2124397efb3409d8e2396347cd25ebad3484112bb47da0015e5e778fe215
@@ -5,9 +5,9 @@ raise "IMPORTANT: sqed gem requires ruby >= 2.1.1" unless recent_ruby
5
5
 
6
6
  require "rmagick"
7
7
 
8
- # Instants take the following
8
+ # Instances take the following
9
9
  # 1) A base image @image
10
- # 2) A target extraction pattern
10
+ # 2) A target extraction pattern, or individually specified attributes
11
11
  #
12
12
  # Return a Sqed::Result
13
13
  #
@@ -23,7 +23,10 @@ class Sqed
23
23
  # initial image which is an instance of ImageMagick::Image, containing background and stage, or just stage
24
24
  attr_accessor :image
25
25
 
26
- # pointer to a combined boundary_finder, layout, and metadata_map pattern, a symbol taken from SqedConfig::EXTRACTION_PATTERNS
26
+ # !optional! A lookup macro that if provided sets boundary_finder, layout, and metadata_map. These can be individually overwritten.
27
+ # Legal values are symbols taken from SqedConfig::EXTRACTION_PATTERNS.
28
+ # DO NOT pass pattern outside of a sqed instance!
29
+ #
27
30
  attr_accessor :pattern
28
31
 
29
32
  # Provide a specific layout, overrides layout metadata taken from pattern
@@ -53,7 +56,7 @@ class Sqed
53
56
  # Provide a boundary_finder, overrides metadata taken from pattern
54
57
  attr_accessor :boundary_finder
55
58
 
56
- def initialize(target_image: nil, target_pattern: :cross, target_layout: nil, has_border: true, boundary_color: :green, use_thumbnail: true, boundary_finder: nil, metadata_map: nil)
59
+ def initialize(target_image: nil, target_pattern: nil, target_layout: nil, has_border: true, boundary_color: :green, use_thumbnail: true, boundary_finder: nil, metadata_map: nil)
57
60
  raise 'extraction pattern not defined' if target_pattern && !SqedConfig::EXTRACTION_PATTERNS.keys.include?(target_pattern)
58
61
 
59
62
  # data, and stubs for results
@@ -62,11 +65,13 @@ class Sqed
62
65
  @stage_boundary = Sqed::Boundaries.new(:internal_box)
63
66
 
64
67
  # extraction metadata
65
- @pattern = (target_pattern || :cross)
68
+ @pattern = target_pattern # not required if target_layout, metadata_map, and boundary_finder are provided
66
69
 
67
70
  @has_border = has_border
68
71
  @boundary_finder = boundary_finder.constantize if boundary_finder
69
- @layout = target_layout || SqedConfig::EXTRACTION_PATTERNS[pattern][:layout]
72
+ @layout = target_layout
73
+ @layout ||= SqedConfig::EXTRACTION_PATTERNS[pattern][:layout] if pattern
74
+
70
75
  @metadata_map = metadata_map
71
76
  @boundary_color = boundary_color
72
77
  @use_thumbnail = use_thumbnail
@@ -77,13 +82,16 @@ class Sqed
77
82
  # @return [Hash]
78
83
  # federate extraction options and apply user provided over-rides
79
84
  def extraction_metadata
80
- data = SqedConfig::EXTRACTION_PATTERNS[pattern]
81
-
82
- data[:boundary_color] = boundary_color
85
+ data = {}
86
+ data = SqedConfig::EXTRACTION_PATTERNS[pattern] if pattern
87
+
88
+ # if pattern is not provided, these must be
83
89
  data[:boundary_finder] = @boundary_finder if boundary_finder
84
- data[:has_border] = has_border
85
90
  data[:target_layout] = layout if layout
86
91
  data[:target_metadata_map] = metadata_map if metadata_map
92
+
93
+ data[:boundary_color] = boundary_color
94
+ data[:has_border] = has_border
87
95
  data[:use_thumbnail] = use_thumbnail
88
96
  data
89
97
  end
@@ -134,8 +142,8 @@ class Sqed
134
142
  end
135
143
 
136
144
  def result
137
- # pattern.nil? is no longer true -> must have values for all extraction_metadata keys
138
- return false if image.nil? || pattern.nil?
145
+ return false if image.nil?
146
+ return false if pattern.nil? && (metadata_map.nil? && layout.nil? && boundary_finder.nil?)
139
147
 
140
148
  extractor = Sqed::Extractor.new(
141
149
  target_boundaries: boundaries,
@@ -1,6 +1,6 @@
1
1
  require 'rmagick'
2
2
 
3
- # An Extractor takes Boundries object and a metadata_map pattern and returns a Sqed::Result
3
+ # An Extractor takes Boundries object and a metadata_map and returns a Sqed::Result
4
4
  #
5
5
  class Sqed::Extractor
6
6
 
@@ -1,3 +1,3 @@
1
1
  class Sqed
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -35,8 +35,8 @@ describe Sqed do
35
35
  end
36
36
 
37
37
  context 'initialization' do
38
- specify 'without providing a pattern assigns :cross' do
39
- expect(s.pattern).to eq(:cross)
38
+ specify 'without providing a pattern assigns nil' do
39
+ expect(s.pattern).to eq(nil)
40
40
  end
41
41
  end
42
42
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Yoder