Skip to content
This repository
Browse code

Remove implementing of to_a in serval cases, use Array method instead.

  • Loading branch information...
commit 4b0ff33e22bc961efce71378ba5a822a93d1fc8f 1 parent 1b5a0b0
janfri authored April 11, 2012
8  Tutorial
@@ -53,7 +53,7 @@ Following types of values are at the moment supported:
53 53
 * Time (e. g. DateTimeOriginal => 2005:09:13 20:08:50)
54 54
 
55 55
 Be aware, if there is only one value in a tag which can hold multiple
56  
-values the result is'nt an array! But you can get one with the to_a
  56
+values the result is'nt an array! But you can get one with the Array
57 57
 method:
58 58
   # only _one_ keyword
59 59
   p1 = MiniExiftool.new 'p1.jpg'
@@ -63,9 +63,9 @@ method:
63 63
   p3.keywords # => ['red', 'yellow', 'green']
64 64
 
65 65
   # if we want to get an array in both cases and don't know
66  
-  # if there is one ore more values set let's take to_a
67  
-  p1.keywords.to_a # => ['red']
68  
-  p3.keywords.to_a # => ['red', 'yellow', 'green']
  66
+  # if there is one ore more values set let's take Array()
  67
+  Array(p1.keywords) # => ['red']
  68
+  Array(p3.keywords) # => ['red', 'yellow', 'green']
69 69
 
70 70
 The Exiftool command-line application has an option (-n) to get values
71 71
 as numbers if possible, in MiniExiftool you can do this with setting
16  lib/mini_exiftool.rb
@@ -349,13 +349,6 @@ def parse_line line
349 349
     else
350 350
       raise MiniExiftool::Error.new("Malformed line #{line.inspect} of exiftool output.")
351 351
     end
352  
-    unless value.respond_to?('to_a')
353  
-      class << value
354  
-        def to_a
355  
-          [self]
356  
-        end
357  
-      end
358  
-    end
359 352
     return [tag, value]
360 353
   end
361 354
 
@@ -440,14 +433,5 @@ def unify tag
440 433
 
441 434
 end
442 435
 
443  
-# Add to_a to Numerical if it's not yet defined
444  
-unless Numeric.instance_methods.include? 'to_a'
445  
-  class Numeric
446  
-    def to_a
447  
-      [self]
448  
-    end
449  
-  end
450  
-end
451  
-
452 436
 # Test if we can run the Exiftool command
453 437
 MiniExiftool.exiftool_version
3  test/test_read.rb
@@ -31,13 +31,12 @@ def test_conversion
31 31
     assert_kind_of String, (@mini_exiftool['SubjectLocation'] || @mini_exiftool['SubjectArea'])
32 32
     assert_kind_of Array, @mini_exiftool['Keywords']
33 33
     assert_kind_of String, @mini_exiftool['SupplementalCategories']
34  
-    assert_kind_of Array, @mini_exiftool['SupplementalCategories'].to_a
35 34
   end
36 35
 
37 36
   def test_list_tags
38 37
     assert_equal ['Orange', 'Rot'], @mini_exiftool['Keywords']
39 38
     assert_equal 'Natur', @mini_exiftool['SupplementalCategories']
40  
-    assert_equal ['Natur'], @mini_exiftool['SupplementalCategories'].to_a
  39
+    assert_equal ['Natur'], Array(@mini_exiftool['SupplementalCategories'])
41 40
   end
42 41
 
43 42
   def test_encoding_conversion
1  test/test_read_numerical.rb
@@ -28,7 +28,6 @@ def test_conversion_numerical
28 28
     assert_kind_of String, (@mini_exiftool_num['SubjectLocation'] || @mini_exiftool_num['SubjectArea'])
29 29
     assert_kind_of Array, @mini_exiftool_num['Keywords']
30 30
     assert_kind_of String, @mini_exiftool_num['SupplementalCategories']
31  
-    assert_kind_of Array, @mini_exiftool_num['SupplementalCategories'].to_a
32 31
   end
33 32
 
34 33
 end

0 notes on commit 4b0ff33

Please sign in to comment.
Something went wrong with that request. Please try again.