Class: HTTPThumbnailerClient::ThumbnailSpec
- Inherits:
-
Object
- Object
- HTTPThumbnailerClient::ThumbnailSpec
- Defined in:
- lib/httpthumbnailer-client/thumbnail_spec.rb
Overview
TODO: support for escaping of ! and ,
Defined Under Namespace
Classes: Builder, EditSpec, InvalidArgumentValueError, InvalidFormatError, MissingArgumentError, MissingOptionKeyNameError, MissingOptionKeyValueError, MissingOptionKeyValuePairError
Instance Attribute Summary collapse
-
#edits ⇒ Object
readonly
Returns the value of attribute edits.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Class Method Summary collapse
- .from_string(string) ⇒ Object
- .options_to_s(options) ⇒ Object
- .parse_options(options) ⇒ Object
- .partition_args_options(args) ⇒ Object
- .split_args(string) ⇒ Object
- .split_edits(string) ⇒ Object
Instance Method Summary collapse
-
#initialize(method, width, height, format, options = {}, edits = []) ⇒ ThumbnailSpec
constructor
A new instance of ThumbnailSpec.
- #to_s ⇒ Object
Constructor Details
#initialize(method, width, height, format, options = {}, edits = []) ⇒ ThumbnailSpec
Returns a new instance of ThumbnailSpec.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/httpthumbnailer-client/thumbnail_spec.rb', line 122 def initialize(method, width, height, format, = {}, edits = []) method.nil? or method.empty? and raise MissingArgumentError, 'method' width.nil? or width.empty? and raise MissingArgumentError, 'width' height.nil? or height.empty? and raise MissingArgumentError, 'height' format.nil? or format.empty? and raise MissingArgumentError, 'format' width !~ /^([0-9]+|input)$/ and raise InvalidArgumentValueError.new('width', width, "an integer or 'input'") height !~ /^([0-9]+|input)$/ and raise InvalidArgumentValueError.new('height', height, "an integer or 'input'") @method = method @width = width @height = height @format = format = @edits = edits end |
Instance Attribute Details
#edits ⇒ Object (readonly)
Returns the value of attribute edits.
105 106 107 |
# File 'lib/httpthumbnailer-client/thumbnail_spec.rb', line 105 def edits @edits end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
105 106 107 |
# File 'lib/httpthumbnailer-client/thumbnail_spec.rb', line 105 def format @format end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
105 106 107 |
# File 'lib/httpthumbnailer-client/thumbnail_spec.rb', line 105 def height @height end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
105 106 107 |
# File 'lib/httpthumbnailer-client/thumbnail_spec.rb', line 105 def method @method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
105 106 107 |
# File 'lib/httpthumbnailer-client/thumbnail_spec.rb', line 105 def end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
105 106 107 |
# File 'lib/httpthumbnailer-client/thumbnail_spec.rb', line 105 def width @width end |
Class Method Details
.from_string(string) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/httpthumbnailer-client/thumbnail_spec.rb', line 107 def self.from_string(string) edits = split_edits(string) spec = edits.shift args = split_args(spec) args, = (args) method, width, height, format = *args.shift(4) # ignore extra args = () edits = edits.map{|e| EditSpec.from_string(e)} new(method, width, height, format, , edits) rescue InvalidFormatError => error raise error.in_spec(string) end |
.options_to_s(options) ⇒ Object
168 169 170 171 172 173 174 175 |
# File 'lib/httpthumbnailer-client/thumbnail_spec.rb', line 168 def self.() .sort_by{|k,v| k}.map do |key, value| raise MissingOptionKeyNameError, value if key.nil? or key.to_s.empty? raise MissingOptionKeyValueError, key if value.nil? or value.to_s.empty? key = key.to_s.gsub('_', '-') if key.kind_of? Symbol "#{key}:#{value}" end end |
.parse_options(options) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/httpthumbnailer-client/thumbnail_spec.rb', line 156 def self.() Hash[.map.with_index do |pair, index| pair.empty? and raise MissingOptionKeyValuePairError, index pair.split(':', 2) end].tap do |map| map.each do |key, value| key.nil? or key.empty? and raise MissingOptionKeyNameError, value value.nil? or value.empty? and raise MissingOptionKeyValueError, key end end end |
.partition_args_options(args) ⇒ Object
150 151 152 153 154 |
# File 'lib/httpthumbnailer-client/thumbnail_spec.rb', line 150 def self.(args) = args.drop_while{|a| not a.include?(':')} args = args.take_while{|a| not a.include?(':')} [args, ] end |
.split_args(string) ⇒ Object
146 147 148 |
# File 'lib/httpthumbnailer-client/thumbnail_spec.rb', line 146 def self.split_args(string) string.split(',') end |
.split_edits(string) ⇒ Object
142 143 144 |
# File 'lib/httpthumbnailer-client/thumbnail_spec.rb', line 142 def self.split_edits(string) string.split('!') end |
Instance Method Details
#to_s ⇒ Object
138 139 140 |
# File 'lib/httpthumbnailer-client/thumbnail_spec.rb', line 138 def to_s [[@method, @width, @height, @format, *self.class.()].join(','), *@edits.map(&:to_s)].join('!') end |