power_converter 0.0.2 → 0.0.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: 1bd5e2306a30c044d98fadc15a1a330cd485f34f
4
- data.tar.gz: ebc9c3bed3649bd24f11fa6564e52a088a766d5a
3
+ metadata.gz: 93f5ce27cd391f22fbebc0a5b98318ebb5e12f79
4
+ data.tar.gz: 3f45e0e53f6af3fc363577aaa02007095b90bfeb
5
5
  SHA512:
6
- metadata.gz: 53124e4dc414751702a99c3b8be7d61dc31cc275141ddc9a5a9fe0fa192a9890580c022e8190675932ea1406dbc362fa8b0877b8201f4b6f34f74aedb4b22a84
7
- data.tar.gz: 93dae5155d1d25aaecac0c218d75a7fa9b734a3e7cf61663d4a427bf0e546d4a9d6a2e1b72c18dfa312debb6853a87a8c034c21582bf3503faf8628e57d19f0b
6
+ metadata.gz: 628a695ed189d9ed1b4922c053a42b538ae930bf049b1dd5c7eafa913bbe0b2251affc88a3c2c7731fa4a57836ac2660fb15c0e014d61877b4c8b9ae9737de23
7
+ data.tar.gz: 58735d7bc79fd56f652cd87f605d48fb931668502e7bccc91f599fed168b75283fefa638928aba38f004010a469ebcb0a0714f1aff5f6de16e9ff1770cbb0006
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/power_converter.svg)](http://badge.fury.io/rb/power_converter)
4
4
  [![Build Status](https://travis-ci.org/jeremyf/power_converter.png?branch=master)](https://travis-ci.org/jeremyf/power_converter)
5
+ [![Code Climate](https://codeclimate.com/github/jeremyf/power_converter/badges/gpa.svg)](https://codeclimate.com/github/jeremyf/power_converter)
6
+ [![Test Coverage](https://codeclimate.com/github/jeremyf/power_converter/badges/coverage.svg)](https://codeclimate.com/github/jeremyf/power_converter)
5
7
  [![Documentation Status](http://inch-ci.org/github/jeremyf/power_converter.svg?branch=master)](http://inch-ci.org/github/jeremyf/power_converter)
6
8
  [![APACHE 2 License](http://img.shields.io/badge/APACHE2-license-blue.svg)](./LICENSE)
7
9
 
@@ -1,5 +1,5 @@
1
1
  # :nodoc:
2
2
  module PowerConverter
3
3
  # :nodoc:
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
@@ -41,8 +41,10 @@ module PowerConverter
41
41
  #
42
42
  # @example
43
43
  # raise ConversionError.new(:boolean, [:hello, :world])
44
- def initialize(value, named_converter)
45
- super("Unable to convert #{value.inspect} to '#{named_converter}'.")
44
+ def initialize(value, options)
45
+ named_converter = options[:to]
46
+ scope = options[:scope]
47
+ super("Unable to convert #{value.inspect} to '#{named_converter}' (scope: #{scope.inspect}.")
46
48
  end
47
49
  end
48
50
 
@@ -127,13 +129,14 @@ module PowerConverter
127
129
  #
128
130
  def convert(value, options = {})
129
131
  named_converter = options.fetch(:to)
132
+ scope = options.fetch(:scope, nil)
130
133
  return value.public_send("to_#{named_converter}") if value.respond_to?("to_#{named_converter}", false)
131
- returning_value = converter_for(named_converter).call(value)
134
+ returning_value = converter_for(named_converter).call(value, *scope)
132
135
  return returning_value unless returning_value.nil?
133
- fail ConversionError.new(value, named_converter)
136
+ fail ConversionError.new(value, options)
134
137
  end
135
138
 
136
- # :nodoc:
139
+ # When building a dynamic conversion method this is its prefix.
137
140
  CONVERSION_METHOD_PREFIX = "convert_to_".freeze
138
141
 
139
142
  # @api public
@@ -196,15 +199,30 @@ module PowerConverter
196
199
  # A convenience method for seeing the names of all converters that have been
197
200
  # defined.
198
201
  #
199
- # @return [Array] of the registered converter's names
202
+ # @return [Array] of the defined converter's names
200
203
  def defined_converter_names
201
204
  @defined_conversions.keys
202
205
  end
203
206
 
204
- # :nodoc:
205
- CONVERSION_METHOD_REGEXP = /\A#{CONVERSION_METHOD_PREFIX}(.*)\Z/.freeze
207
+ # Useful for when you want to know if a method name is a valid conversion
208
+ # method name.
209
+ CONVERSION_METHOD_REGEXP = /\A#{CONVERSION_METHOD_PREFIX}(.+)\Z/.freeze
206
210
 
207
- # :nodoc:
211
+ # @api private
212
+ # @since 0.0.2
213
+ #
214
+ # Handle attempts to call module level conversions directly off of the
215
+ # PowerConverter module.
216
+ #
217
+ # @example
218
+ # PowerConverter.define_conversion_for(:boolean) { |input| ... }
219
+ # PowerConverter.convert_to_boolean(a_value)
220
+ #
221
+ # @param method_name [Symbol]
222
+ # @param args [Array] splat arguements that would be passed on-ward
223
+ # @param block [#call]
224
+ #
225
+ # @see PowerConverter::CONVERSION_METHOD_PREFIX
208
226
  def method_missing(method_name, *args, &block)
209
227
  named_converter = extract_named_converter_from(method_name)
210
228
  if named_converter
@@ -215,14 +233,37 @@ module PowerConverter
215
233
  end
216
234
  private_class_method :method_missing
217
235
 
218
- # :nodoc:
236
+ # @api private
237
+ # @since 0.0.2
238
+ #
239
+ # Based on the given method_name extract the name of a defined converter.
240
+ #
241
+ # @param method_name [#to_s] a method name that could be in a named conversion
242
+ # method format
243
+ #
244
+ # @return [String, nil] Will return the named_converter a match is found,
245
+ # otherwise nil
219
246
  def extract_named_converter_from(method_name)
220
247
  match = method_name.to_s.match(CONVERSION_METHOD_REGEXP)
221
248
  match.captures[0] if match
222
249
  end
223
250
  private_class_method :extract_named_converter_from
224
251
 
225
- # :nodoc:
252
+ # @api private
253
+ # @since 0.0.2
254
+ #
255
+ # Determine if the conversion module responds to a potentially registered
256
+ # conversion method.
257
+ #
258
+ # @example
259
+ # PowerConverter.define_conversion_for(:boolean) { |input| ... }
260
+ # PowerConverter.respond_to?(:convert_to_boolean)
261
+ # => true
262
+ #
263
+ # @param method_name [Symbol] the name of the method that the object might
264
+ # respond to
265
+ # @param include_private [Boolean] if true skip private/protected methods
266
+ # otherwise include them
226
267
  def respond_to_missing?(method_name, include_private = false)
227
268
  named_converter = extract_named_converter_from(method_name)
228
269
  if named_converter
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "minitest", "~> 5.5"
25
25
  spec.add_development_dependency "rubocop", "~> 0.2"
26
+ spec.add_development_dependency "simplecov", "~> 0.9"
27
+ spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4"
26
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-03 00:00:00.000000000 Z
11
+ date: 2015-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: codeclimate-test-reporter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.4'
69
97
  description: A lightweight library to define object conversion methods/modules.
70
98
  email:
71
99
  - jeremy.n.friesen@gmail.com