woody-decorators 2.1.0 → 2.2.0

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: 7e5794d443137b77cba787fa1e74c3dbc4815f77
4
- data.tar.gz: e857512b417f9daf4ee71bd7826f81f99cf379f1
3
+ metadata.gz: 998199005ed2235da9f97f8f5effc60329e83ca0
4
+ data.tar.gz: d11091f950adbde26fea150ba849503110ceef14
5
5
  SHA512:
6
- metadata.gz: c44defd17e952864968fee45fff3c8b9ef5b85c574bca404b300b66746dbab9ab28f7cf1ccd93a4304b4c4b964e72cdd884dcb2a0d223a4f466a695edd8767b9
7
- data.tar.gz: 2578e17c9e63b0644404cc60e966d4e0324d750d5c57a84e020d2e199d6068c82b3b963b032ec27724c37e8916f388e3ec1363cf7c9c85847aa410a0e4779105
6
+ metadata.gz: e5dc61f0ee15bce38a8c247e00e8a555191407eb7774a17d6a77f3a40ca31b309d6b37b6691d3b4f1d90bd4f9472acb5bcd9e7eb4a4cd76da9ff15a2d25b27a2
7
+ data.tar.gz: 7c64a2c998ab09f282a54cec281085427485572360ddd956e545d86f9a14bb9c913da24fc32d25844ffe15a0e656a985b06a33f59d3f8c37fcbf65bc9817e4de
@@ -1,5 +1,5 @@
1
1
  module Woody
2
2
  module Decorators
3
- VERSION = "2.1.0".freeze
3
+ VERSION = "2.2.0".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,61 @@
1
+ module Woody
2
+ module Decorators
3
+ module Helper
4
+ class AspectRatio
5
+ def initialize(height, width)
6
+ @height = height
7
+ @width = width
8
+ end
9
+
10
+ def class_name
11
+ return format_class_name("landscape", "16-9") unless valid_dimensions
12
+
13
+ case ratio
14
+ when "1:1"
15
+ "square"
16
+ when "16:9", "4:3", "9:16", "5:4"
17
+ format(CLASS_NAME_FORMAT, orientation, ratio("-"))
18
+ else
19
+ format(CLASS_NAME_FORMAT, orientation, default_ratio)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ CLASS_NAME_FORMAT = "%s_ar%s".freeze
26
+
27
+ def format_class_name(orientation, ratio)
28
+ format(CLASS_NAME_FORMAT, orientation, ratio)
29
+ end
30
+
31
+ def default_ratio
32
+ orientation == "landscape" ? "16-9" : "9-16"
33
+ end
34
+
35
+ def ratio(delimiter = ":")
36
+ format("%d%s%d", ratio_width, delimiter, ratio_height)
37
+ end
38
+
39
+ def gcd
40
+ @height.gcd(@width)
41
+ end
42
+
43
+ def ratio_width
44
+ @width / gcd
45
+ end
46
+
47
+ def ratio_height
48
+ @height / gcd
49
+ end
50
+
51
+ def orientation
52
+ @width > @height ? "landscape" : "portrait"
53
+ end
54
+
55
+ def valid_dimensions
56
+ !@width.nil? && !@height.nil?
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -4,6 +4,7 @@ require "wes/data/api/challenge"
4
4
  require "wes/data/api/submission"
5
5
  require "woody/decorators/base"
6
6
  require "woody/decorators/video_transcoding_state"
7
+ require "woody/decorators/helper/aspect_ratio"
7
8
 
8
9
  module Woody
9
10
  module Decorators
@@ -14,7 +15,10 @@ module Woody
14
15
  end
15
16
 
16
17
  def aspect_ratio
17
- "landscape_ar16-9" # TODO
18
+ @aspect_ratio ||= Helper::AspectRatio.new(
19
+ @model.height,
20
+ @model.width
21
+ ).class_name
18
22
  end
19
23
 
20
24
  def brand
@@ -61,16 +65,6 @@ module Woody
61
65
  @aws_config ||= @config.aws
62
66
  end
63
67
 
64
- def aspect_ratios
65
- [
66
- "square",
67
- "landscape_ar16-9",
68
- "landscape_ar4-3",
69
- "portrait_ar9-16",
70
- "portrait_ar5-4"
71
- ]
72
- end
73
-
74
68
  def dev?
75
69
  Wes::Cloudkit.dev?
76
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: woody-decorators
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-21 00:00:00.000000000 Z
11
+ date: 2016-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -152,6 +152,7 @@ files:
152
152
  - lib/woody/decorators/challenge_question.rb
153
153
  - lib/woody/decorators/collective.rb
154
154
  - lib/woody/decorators/creator_user.rb
155
+ - lib/woody/decorators/helper/aspect_ratio.rb
155
156
  - lib/woody/decorators/submission.rb
156
157
  - lib/woody/decorators/user.rb
157
158
  - lib/woody/decorators/video.rb