caracal 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad435a7228e3d48426661c2fbebd7df0db88628b
4
- data.tar.gz: f4016cb90243760f4751fdb7cfa918295bb040c3
3
+ metadata.gz: 6b30278ea80ad76f441a2ea9f6c593882dd949a3
4
+ data.tar.gz: ba375c68ca17a0d4a02c1a6bd94014d981c9ad71
5
5
  SHA512:
6
- metadata.gz: f9f52217eef965b931bfe4d200cddf17149b963f1fb0c56d50f7a0421d30aae9e640ab130d4a9be43dd93748895a517aa50e5d9d4d4b74a4c93a321177af9c2a
7
- data.tar.gz: 7653f32b1cb7eafb75acfc44020ac7fe9be7c112db1060b5777a732a4a032c6dabf1a5a9c9ead3e6694cfb3506f487ed8e90181b9e7eeb6f63177deb1c08e8ad
6
+ metadata.gz: aeeaa43517f427a98e241a16e630a8a7382679322064dea47a044043960a2ed05cc8ffcc9e1a3a53e9d6d94d9584c719e37ea643866aa9c1de5b4ccfb0a36b2b
7
+ data.tar.gz: 36f3e961946d533924e25a0b3f32470762f16e51d33ef3b679c242a55594e1d112e55125dae26ec0bb1e6432832a39eb3c0743873e578a1171c2e6d121320361
@@ -14,6 +14,7 @@ module Caracal
14
14
  #-------------------------------------------------------------
15
15
 
16
16
  # constants
17
+ const_set(:DEFAULT_IMAGE_PPI, 72) # pixels per inch
17
18
  const_set(:DEFAULT_IMAGE_WIDTH, 0) # units in pixels. (will cause error)
18
19
  const_set(:DEFAULT_IMAGE_HEIGHT, 0) # units in pixels. (will cause error)
19
20
  const_set(:DEFAULT_IMAGE_ALIGN, :left)
@@ -25,6 +26,7 @@ module Caracal
25
26
  # accessors
26
27
  attr_reader :image_url
27
28
  attr_reader :image_data
29
+ attr_reader :image_ppi
28
30
  attr_reader :image_width
29
31
  attr_reader :image_height
30
32
  attr_reader :image_align
@@ -36,6 +38,7 @@ module Caracal
36
38
 
37
39
  # initialization
38
40
  def initialize(options={}, &block)
41
+ @image_ppi = DEFAULT_IMAGE_PPI
39
42
  @image_width = DEFAULT_IMAGE_WIDTH
40
43
  @image_height = DEFAULT_IMAGE_HEIGHT
41
44
  @image_align = DEFAULT_IMAGE_ALIGN
@@ -54,10 +57,17 @@ module Caracal
54
57
 
55
58
  #=============== GETTERS ==============================
56
59
 
57
- [:width, :height, :top, :bottom, :left, :right].each do |m|
60
+ [:width, :height].each do |m|
58
61
  define_method "formatted_#{ m }" do
59
62
  value = send("image_#{ m }")
60
- pixels_to_emus(value)
63
+ pixels_to_emus(value, image_ppi)
64
+ end
65
+ end
66
+
67
+ [:top, :bottom, :left, :right].each do |m|
68
+ define_method "formatted_#{ m }" do
69
+ value = send("image_#{ m }")
70
+ pixels_to_emus(value, 72)
61
71
  end
62
72
  end
63
73
 
@@ -69,7 +79,7 @@ module Caracal
69
79
  #=============== SETTERS ==============================
70
80
 
71
81
  # integers
72
- [:width, :height, :top, :bottom, :left, :right].each do |m|
82
+ [:ppi, :width, :height, :top, :bottom, :left, :right].each do |m|
73
83
  define_method "#{ m }" do |value|
74
84
  instance_variable_set("@image_#{ m }", value.to_i)
75
85
  end
@@ -93,7 +103,7 @@ module Caracal
93
103
  #=============== VALIDATION ==============================
94
104
 
95
105
  def valid?
96
- dims = [:width, :height, :top, :bottom, :left, :right].map { |m| send("image_#{ m }") }
106
+ dims = [:ppi, :width, :height, :top, :bottom, :left, :right].map { |m| send("image_#{ m }") }
97
107
  dims.all? { |d| d > 0 }
98
108
  end
99
109
 
@@ -108,9 +118,9 @@ module Caracal
108
118
  [:url, :width, :height, :align, :top, :bottom, :left, :right]
109
119
  end
110
120
 
111
- def pixels_to_emus(value)
121
+ def pixels_to_emus(value, ppi)
112
122
  pixels = value.to_i
113
- inches = pixels / 72.0
123
+ inches = pixels / ppi.to_f
114
124
  emus_per_inch = 914400
115
125
 
116
126
  emus = (inches * emus_per_inch).to_i
@@ -1,3 +1,3 @@
1
1
  module Caracal
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
@@ -4,6 +4,7 @@ describe Caracal::Core::Models::ImageModel do
4
4
  subject do
5
5
  described_class.new do
6
6
  url 'https://www.google.com/images/srpr/logo11w.png'
7
+ ppi 96
7
8
  width 250
8
9
  height 200
9
10
  align :right
@@ -24,6 +25,7 @@ describe Caracal::Core::Models::ImageModel do
24
25
 
25
26
  # constants
26
27
  describe 'constants' do
28
+ it { expect(described_class::DEFAULT_IMAGE_PPI).to eq 72 }
27
29
  it { expect(described_class::DEFAULT_IMAGE_WIDTH).to eq 0 }
28
30
  it { expect(described_class::DEFAULT_IMAGE_HEIGHT).to eq 0 }
29
31
  it { expect(described_class::DEFAULT_IMAGE_ALIGN).to eq :left }
@@ -37,6 +39,7 @@ describe Caracal::Core::Models::ImageModel do
37
39
  describe 'accessors' do
38
40
  it { expect(subject.image_url).to eq 'https://www.google.com/images/srpr/logo11w.png' }
39
41
  it { expect(subject.image_data).to eq nil }
42
+ it { expect(subject.image_ppi).to eq 96 }
40
43
  it { expect(subject.image_width).to eq 250 }
41
44
  it { expect(subject.image_height).to eq 200 }
42
45
  it { expect(subject.image_align).to eq :right }
@@ -57,8 +60,22 @@ describe Caracal::Core::Models::ImageModel do
57
60
 
58
61
  #=============== GETTERS ==========================
59
62
 
60
- # emu conversions
61
- [:width, :height, :top, :bottom, :left, :right].each do |m|
63
+ # emu conversions (dimensions)
64
+ [:width, :height].each do |m|
65
+ describe ".formatted_#{ m }" do
66
+ let(:actual) { subject.send("formatted_#{ m }") }
67
+
68
+ before do
69
+ allow(subject).to receive("image_#{ m }").and_return(540)
70
+ allow(subject).to receive("image_ppi").and_return(96)
71
+ end
72
+
73
+ it { expect(actual).to eq 5143500 }
74
+ end
75
+ end
76
+
77
+ # emu conversions (margins)
78
+ [:top, :bottom, :left, :right].each do |m|
62
79
  describe ".formatted_#{ m }" do
63
80
  let(:actual) { subject.send("formatted_#{ m }") }
64
81
 
@@ -68,6 +85,9 @@ describe Caracal::Core::Models::ImageModel do
68
85
  end
69
86
  end
70
87
 
88
+ # .relationship_target
89
+
90
+
71
91
 
72
92
  #=============== SETTERS ==========================
73
93
 
@@ -85,6 +105,13 @@ describe Caracal::Core::Models::ImageModel do
85
105
  it { expect(subject.image_data).to eq 'PNG Data follows here' }
86
106
  end
87
107
 
108
+ # .ppi
109
+ describe '.ppi' do
110
+ before { subject.ppi(108) }
111
+
112
+ it { expect(subject.image_ppi).to eq 108 }
113
+ end
114
+
88
115
  # .width
89
116
  describe '.width' do
90
117
  before { subject.width(300) }
@@ -171,7 +198,7 @@ describe Caracal::Core::Models::ImageModel do
171
198
 
172
199
  # .pixels_to_emus
173
200
  describe '.pixels_to_emus' do
174
- let(:actual) { subject.send(:pixels_to_emus, value) }
201
+ let(:actual) { subject.send(:pixels_to_emus, value, 72) }
175
202
 
176
203
  describe 'when argument is nil' do
177
204
  let(:value) { nil }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caracal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trade Infomatics
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-05 00:00:00.000000000 Z
12
+ date: 2014-09-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri