id3 0.5.0 → 1.0.0.pre4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +14 -0
- data/LICENSE.html +8 -1
- data/README.md +39 -0
- data/docs/ID3_comparison.html +10 -2
- data/docs/ID3_comparison2.html +29 -21
- data/docs/ID3v2_frames_overview.txt +172 -35
- data/{lib → docs}/hexdump.rb +0 -0
- data/docs/index.html +29 -9
- data/lib/helpers/hash_extensions.rb +20 -0
- data/lib/helpers/hexdump.rb +136 -0
- data/lib/helpers/invert_hash.rb +128 -0
- data/lib/helpers/recursive_helper.rb +39 -0
- data/lib/helpers/restricted_ordered_hash.rb +88 -0
- data/lib/helpers/ruby_1.8_1.9_compatibility.rb +62 -0
- data/lib/id3.rb +23 -1252
- data/lib/id3/audiofile.rb +261 -0
- data/lib/id3/constants.rb +292 -0
- data/lib/id3/frame.rb +178 -0
- data/lib/id3/frame_array.rb +19 -0
- data/lib/id3/generic_tag.rb +73 -0
- data/lib/id3/id3.rb +159 -0
- data/lib/id3/io_extensions.rb +44 -0
- data/lib/id3/module_methods.rb +127 -0
- data/lib/id3/string_extensions.rb +40 -0
- data/lib/id3/tag1.rb +131 -0
- data/lib/id3/tag2.rb +261 -0
- metadata +87 -58
- data/README +0 -18
- data/docs/ID3v2_frames_comparison.txt +0 -197
- data/lib/invert_hash.rb +0 -105
metadata
CHANGED
@@ -1,76 +1,105 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
1
|
+
--- !ruby/object:Gem::Specification
|
4
2
|
name: id3
|
5
|
-
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
|
8
|
-
summary: A native ID3 tag library for Ruby, which does not depend on architecture-dependent C-libraries. It supports reading and writing ID3-tag versions 1.0, 1.1, and 2.2.x, 2,3.x, 2,4.x\n http://www.unixgods.org/~tilo/Ruby/ID3
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: tools@unixgods.org
|
12
|
-
homepage: http://www.unixgods.org/~tilo/Ruby/ID3
|
13
|
-
rubyforge_project:
|
14
|
-
description: ID3 is a native ruby library for reading and writing ID3 tag versions 1.0, 1.1, and 2.2.x, 2,3.x, 2,4.x
|
15
|
-
autorequire: id3
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: false
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.pre4
|
5
|
+
prerelease: 6
|
25
6
|
platform: ruby
|
26
|
-
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
|
-
authors:
|
7
|
+
authors:
|
30
8
|
- Tilo Sloboda
|
31
|
-
|
32
|
-
|
33
|
-
|
9
|
+
autorequire: id3
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: active_support
|
16
|
+
requirement: &7397560 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *7397560
|
25
|
+
description: ID3 is a native ruby library for reading and writing ID3 tag versions
|
26
|
+
1.0, 1.1, and 2.2.x, 2,3.x, 2,4.x
|
27
|
+
email: tilo.sloboda@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
34
32
|
- docs/ID3_comparison.html
|
35
|
-
- docs/
|
36
|
-
- docs/
|
33
|
+
- docs/hexdump.rb
|
34
|
+
- docs/Class_Frame.html
|
37
35
|
- docs/ID3v2_frames_overview.txt
|
38
|
-
- docs/
|
36
|
+
- docs/Class_AudioFile.html
|
37
|
+
- docs/ID3v2_frames_comparison.html
|
38
|
+
- docs/index.html
|
39
39
|
- docs/ID3_comparison2.html
|
40
|
+
- docs/Class_Tag2.html
|
41
|
+
- docs/Module_ID3.html
|
40
42
|
- docs/id3.html
|
41
|
-
- docs/
|
42
|
-
- docs/
|
43
|
-
- docs/ID3-Standards
|
44
|
-
- docs/ID3-Standards/id3v2.3.0.html
|
43
|
+
- docs/ID3-Standards/id3v2-00.html
|
44
|
+
- docs/ID3-Standards/id3v2.4.0-changes.txt
|
45
45
|
- docs/ID3-Standards/id3v2.4.0-frames.html
|
46
|
+
- docs/ID3-Standards/id3v2.3.0.html
|
46
47
|
- docs/ID3-Standards/id3v2.4.0-frames.txt
|
47
|
-
- docs/ID3-Standards/id3v2-00.txt
|
48
48
|
- docs/ID3-Standards/id3v2.4.0-structure.txt
|
49
|
+
- docs/ID3-Standards/id3v2.4.0-changes.html
|
49
50
|
- docs/ID3-Standards/id3v2.3.0.txt
|
50
|
-
- docs/ID3-Standards/id3v2.4.0-changes.txt
|
51
51
|
- docs/ID3-Standards/id3v2.4.0-structure.html
|
52
|
-
- docs/ID3-Standards/id3v2
|
53
|
-
- docs/
|
54
|
-
- docs/ID3v2_frames_comparison.html
|
55
|
-
- lib/hexdump.rb
|
52
|
+
- docs/ID3-Standards/id3v2-00.txt
|
53
|
+
- docs/Class_Tag1.html
|
56
54
|
- lib/id3.rb
|
57
|
-
- lib/
|
55
|
+
- lib/id3/module_methods.rb
|
56
|
+
- lib/id3/id3.rb
|
57
|
+
- lib/id3/constants.rb
|
58
|
+
- lib/id3/tag2.rb
|
59
|
+
- lib/id3/frame.rb
|
60
|
+
- lib/id3/generic_tag.rb
|
61
|
+
- lib/id3/audiofile.rb
|
62
|
+
- lib/id3/io_extensions.rb
|
63
|
+
- lib/id3/tag1.rb
|
64
|
+
- lib/id3/frame_array.rb
|
65
|
+
- lib/id3/string_extensions.rb
|
66
|
+
- lib/helpers/hexdump.rb
|
67
|
+
- lib/helpers/ruby_1.8_1.9_compatibility.rb
|
68
|
+
- lib/helpers/invert_hash.rb
|
69
|
+
- lib/helpers/recursive_helper.rb
|
70
|
+
- lib/helpers/hash_extensions.rb
|
71
|
+
- lib/helpers/restricted_ordered_hash.rb
|
58
72
|
- LICENSE.html
|
59
73
|
- index.html
|
60
|
-
- README
|
74
|
+
- README.md
|
61
75
|
- CHANGES
|
62
|
-
|
63
|
-
|
64
|
-
|
76
|
+
homepage: http://www.unixgods.org/~tilo/Ruby/ID3
|
77
|
+
licenses: []
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options:
|
65
80
|
- --title
|
66
|
-
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
81
|
+
- Native ID3 Ruby Library - uniform acecss to ID3v1 and ID3v2 tags
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>'
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 1.3.1
|
73
96
|
requirements: []
|
74
|
-
|
75
|
-
|
76
|
-
|
97
|
+
rubyforge_project:
|
98
|
+
- none
|
99
|
+
rubygems_version: 1.8.15
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: A native ID3 tag library for Ruby, which does not depend on architecture-dependent
|
103
|
+
C-libraries. It supports reading and writing ID3-tag versions 1.0, 1.1, and 2.2.x,
|
104
|
+
2,3.x, 2,4.x\n http://www.unixgods.org/~tilo/Ruby/ID3
|
105
|
+
test_files: []
|
data/README
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
|
2
|
-
This is a BETA-RELEASE of a native Ruby ID3-library.
|
3
|
-
|
4
|
-
Author: Tilo Sloboda <tools-NOSPAM@unixgods.org>
|
5
|
-
|
6
|
-
Home Page: http://www.unixgods.org/~tilo/Ruby/ID3
|
7
|
-
|
8
|
-
License: http://www.unixgods.org/~tilo/artistic-license.html
|
9
|
-
|
10
|
-
|
11
|
-
NOTE:
|
12
|
-
|
13
|
-
This is a beta release.. so, if you think there are some problems,
|
14
|
-
errors, inconsistencies, or there is something missing, please contact
|
15
|
-
the author - THANK YOU! :-)
|
16
|
-
|
17
|
-
|
18
|
-
|
@@ -1,197 +0,0 @@
|
|
1
|
-
|
2
|
-
===========================
|
3
|
-
Comparison of ID3v2 Frames:
|
4
|
-
===========================
|
5
|
-
|
6
|
-
This document contains a side-by-side comparison over the frames used
|
7
|
-
in the 3 different versions of the informal ID3v2 standard:
|
8
|
-
v2.2.0, v2.3.0 and v2.4.0
|
9
|
-
|
10
|
-
This document is a compilation of information which is available in the
|
11
|
-
documents listed below. The original documents Copyright notices apply.
|
12
|
-
|
13
|
-
ID3 v1.0 : http://www.id3.org/id3v1.html
|
14
|
-
ID3 v1.1 : http://www.egr.uri.edu/~kovacsp/mp3/ID3-Tag.html
|
15
|
-
|
16
|
-
|
17
|
-
ID3v2 2.0: http://www.id3.org/id3v2-00.txt
|
18
|
-
ID3v2 3.0: http://www.id3.org/id3v2.3.0.txt
|
19
|
-
ID3v2 4.0: http://www.id3.org/id3v2.4.0-changes.txt
|
20
|
-
http://www.id3.org/id3v2.4.0-structure.txt
|
21
|
-
http://www.id3.org/id3v2.4.0-frames.txt
|
22
|
-
|
23
|
-
Please refer to the original documents listed above, for any information
|
24
|
-
regarding the ID3v2 standards.
|
25
|
-
|
26
|
-
|
27
|
-
Author: Tilo Sloboda, Thu, 17 Oct 2002 00:26:54 -0700
|
28
|
-
|
29
|
-
|
30
|
-
References:
|
31
|
-
id3lib-3.8.0 id3lib-3.8.0/include/id3/globals.h
|
32
|
-
|
33
|
-
NOTE: the symbolic names used in the leftmost column are derived
|
34
|
-
from the names used in id3lib-3.8.0
|
35
|
-
The symbolic name CRYPTEDMETA is not part of id3lib-3.8.0
|
36
|
-
|
37
|
-
Legend:
|
38
|
-
|
39
|
-
-- : depreciated frame
|
40
|
-
|
41
|
-
-> : replaced by (all frames listed before this one are replaced)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
================================================================================
|
46
|
-
ID3v2 version
|
47
|
-
symbolic names 2.0 3.0 4.0 comments
|
48
|
-
================================================================================
|
49
|
-
|
50
|
-
CONTENTGROUP TT1 TIT1 TIT1 content group description
|
51
|
-
TITLE TT2 TIT2 TIT2 title/songname/content description
|
52
|
-
SUBTITLE TT3 TIT3 TIT3 subtitle/description refinement
|
53
|
-
|
54
|
-
LEADARTIST TP1 TPE1 TPE1 lead performer(s)/soloist(s)
|
55
|
-
BAND TP2 TPE2 TPE2 band/orchestra/accompaniment
|
56
|
-
CONDUCTOR TP3 TPE3 TPE3 conductor/performer refinement
|
57
|
-
MIXARTIST TP4 TPE4 TPE4 interpreted, remixed, modified by
|
58
|
-
|
59
|
-
COMPOSER TCM TCOM TCOM composer
|
60
|
-
LYRICIST TXT` TEXT TEXT lyricist/text writer
|
61
|
-
|
62
|
-
LANGUAGE TLA TLAN TLAN language(s)
|
63
|
-
CONTENTTYPE TCO TCON TCON content type
|
64
|
-
|
65
|
-
ALBUM TAL TALB TALB album/movie/show title
|
66
|
-
|
67
|
-
TRACKNUM TRK TRCK TRCK track number/position in set
|
68
|
-
PARTINSET TPA TPOS TPOS part of set
|
69
|
-
|
70
|
-
ISRC TRC TSRC TSRC international standard recording code
|
71
|
-
|
72
|
-
--------------------------------------------------------------------------------
|
73
|
-
DATE TDA TDAT date
|
74
|
-
YEAR TYE TYER year
|
75
|
-
TIME TIM TIME time
|
76
|
-
RECORDINGDATES TRD TRDA recording dates
|
77
|
-
RECORDINGTIME -> TDRC recording time
|
78
|
-
--------------------------------------------------------------------------------
|
79
|
-
ORIGYEAR TOR TORY original release year
|
80
|
-
ORIGRELEASETIME -> TDOR original release time
|
81
|
-
--------------------------------------------------------------------------------
|
82
|
-
|
83
|
-
BPM TBP TBPM TBPM beats per minute
|
84
|
-
|
85
|
-
MEDIATYPE TMT TMED TMED media type
|
86
|
-
FILETYPE TFT TFLT TFLT file type
|
87
|
-
COPYRIGHT TCR TCOP TCOP copyright message
|
88
|
-
|
89
|
-
PUBLISHER TPB TPUB TPUB pblisher
|
90
|
-
ENCODEDBY TEN TENC TENC encoded by
|
91
|
-
ENCODERSETTINGS TSS TSSE TSSE software/hardware + settings for encoding
|
92
|
-
|
93
|
-
SONGLEN TLE TLEN TLEN length (ms)
|
94
|
-
--------------------------------------------------------------------------------
|
95
|
-
SIZE TSI TSIZ -- size (bytes)
|
96
|
-
--------------------------------------------------------------------------------
|
97
|
-
|
98
|
-
PLAYLISTDELAY TDY TDLY TDLY playlist delay
|
99
|
-
INITIALKEY TKE TKEY TKEY initial key
|
100
|
-
|
101
|
-
ORIGALBUM TOT TOAL TOAL original album/movie/show title
|
102
|
-
ORIGFILENAME TOF TOFN TOFN original filename
|
103
|
-
ORIGARTIST TOA TOPE TOPE original artist(s)/performer(s)
|
104
|
-
ORIGLYRICIST TOL TOLY TOLY original lyricist(s)/text writer(s)
|
105
|
-
|
106
|
-
FILEOWNER TOWN TOWN file owner/licensee
|
107
|
-
NETRADIOSTATION TRSN TRSN internet radio station name
|
108
|
-
NETRADIOOWNER TRSO TRSO internet radio station owner
|
109
|
-
|
110
|
-
SETSUBTITLE TSST set subtitle
|
111
|
-
MOOD TMOO mood
|
112
|
-
PRODUCEDNOTICE TPRO produced notice
|
113
|
-
ENCODINGTIME TDEN encoding time
|
114
|
-
RELEASETIME TDRL release time
|
115
|
-
TAGGINGTIME TDTG tagging time
|
116
|
-
|
117
|
-
ALBUMSORTORDER TSOA album sort order
|
118
|
-
PERFORMERSORTORDER TSOP performer sort order
|
119
|
-
TITLESORTORDER TSOT title sort order
|
120
|
-
|
121
|
-
USERTEXT TXX TXXX TXXX user defined text information frame
|
122
|
-
|
123
|
-
|
124
|
-
WWWAUDIOFILE WAF WOAF WOAF official audio file webpage
|
125
|
-
WWWARTIST WAR WOAR WOAR official artist/performer webpage
|
126
|
-
WWWAUDIOSOURCE WAS WOAS WOAS official audion source webpage
|
127
|
-
WWWCOMMERCIALINFO WCM WCOM WCOM commercial information
|
128
|
-
WWWCOPYRIGHT WCP WCOP WCOP copyright/legal information
|
129
|
-
WWWPUBLISHER WPB WPUB WPUB publishers official webpage
|
130
|
-
|
131
|
-
WWWRADIOPAGE WORS WORS official internet radio station homepage
|
132
|
-
WWWPAYMENT WPAY WPAY payment
|
133
|
-
|
134
|
-
WWWUSER WXX WXXX WXXX user defined URL link frame
|
135
|
-
|
136
|
-
--------------------------------------------------------------------------------
|
137
|
-
INVOLVEDPEOPLE IPL IPLS involved people list
|
138
|
-
MUSICIANCREDITLIST -> TMCL musician credits list
|
139
|
-
INVOLVEDPEOPLE2 -> TIPL involved people list
|
140
|
-
--------------------------------------------------------------------------------
|
141
|
-
|
142
|
-
UNSYNCEDLYRICS ULT USLT USLT unsynchronised lyrics/text transcription
|
143
|
-
COMMENT COM COMM COMM comments
|
144
|
-
|
145
|
-
TERMSOFUSE USER USER terms of use
|
146
|
-
|
147
|
-
|
148
|
-
================================================================================
|
149
|
-
ID3v2 version
|
150
|
-
symbolic names 2.0 3.0 4.0 comments
|
151
|
-
================================================================================
|
152
|
-
|
153
|
-
CDID MCI MCDI MCDI music CD identifier
|
154
|
-
EVENTTIMING ETC ETCO ETCO event timing codes
|
155
|
-
MPEGLOOKUP MLL MLLT MLLT MPEG location lookup table
|
156
|
-
|
157
|
-
SYNCEDTEMPO STC SYTC SYTC synchronised tempo codes
|
158
|
-
SYNCEDLYRICS SLT SYLT SYLT synchronised lyrics/text
|
159
|
-
|
160
|
-
--------------------------------------------------------------------------------
|
161
|
-
VOLUMEADJ RVA RVAD relative volume adjustment
|
162
|
-
VOLUMEADJ2 -> RVA2 relative volume adjustment (2)
|
163
|
-
--------------------------------------------------------------------------------
|
164
|
-
EQUALIZATION EQU EQUA equalization
|
165
|
-
EQUALIZATION2 -> EQU2 equalization (2)
|
166
|
-
--------------------------------------------------------------------------------
|
167
|
-
|
168
|
-
REVERB REV RVRB RVRB reverb
|
169
|
-
PICTURE PIC APIC APIC attached picture
|
170
|
-
GENERALOBJECT GEO GEOB GEOB general encapsulated object
|
171
|
-
|
172
|
-
PLAYCOUNTER CNT PCNT PCNT play counter
|
173
|
-
POPULARIMETER POP POPM POPM popularimeter
|
174
|
-
|
175
|
-
BUFFERSIZE BUF RBUF RBUF recommended buffer size
|
176
|
-
|
177
|
-
CRYPTEDMETA CRM encrypted meta frame
|
178
|
-
AUDIOCRYPTO CRA AENC AENC audio encryption
|
179
|
-
|
180
|
-
LINKEDINFO LNK LINK LINK linked information
|
181
|
-
|
182
|
-
POSITIONSYNC POSS POSS position synchronisation frame
|
183
|
-
|
184
|
-
COMMERCIAL COMR COMR commercial frame
|
185
|
-
CRYPTOREG ENCR ENCR encryption method registration
|
186
|
-
GROUPINGREG GRID GRID group indentification registration
|
187
|
-
PRIVATE PRIV PRIV private frame
|
188
|
-
|
189
|
-
OWNERSHIP OWNE ownership frame
|
190
|
-
SIGNATURE SIGN signature frame
|
191
|
-
SEEKFRAME SEEK seek frame
|
192
|
-
AUDIOSEEKPOINT ASPI audio seek point index
|
193
|
-
|
194
|
-
================================================================================
|
195
|
-
ID3v2 version
|
196
|
-
symbolic names 2.0 3.0 4.0 comments
|
197
|
-
================================================================================
|
data/lib/invert_hash.rb
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
# ==============================================================================
|
2
|
-
# EXTENDING CLASS HASH
|
3
|
-
# ==============================================================================
|
4
|
-
#
|
5
|
-
# (C) Copyright 2004 by Tilo Sloboda <tools@unixgods.org>
|
6
|
-
#
|
7
|
-
# updated: Time-stamp: <Sat 18-Dec-2004 12:44:13 Tilo Sloboda>
|
8
|
-
#
|
9
|
-
# License:
|
10
|
-
# Freely available under the terms of the OpenSource "Artistic License"
|
11
|
-
# in combination with the Addendum A (below)
|
12
|
-
#
|
13
|
-
# In case you did not get a copy of the license along with the software,
|
14
|
-
# it is also available at: http://www.unixgods.org/~tilo/artistic-license.html
|
15
|
-
#
|
16
|
-
# Addendum A:
|
17
|
-
# THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU!
|
18
|
-
# SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
19
|
-
# REPAIR OR CORRECTION.
|
20
|
-
#
|
21
|
-
# IN NO EVENT WILL THE COPYRIGHT HOLDERS BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL,
|
22
|
-
# SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY
|
23
|
-
# TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
|
24
|
-
# INACCURATE OR USELESS OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
|
25
|
-
# TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF THE COPYRIGHT HOLDERS OR OTHER PARTY HAS BEEN
|
26
|
-
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
27
|
-
|
28
|
-
# ==============================================================================
|
29
|
-
#
|
30
|
-
# Homepage: http://www.unixgods.org/~tilo/Ruby/invert_hash.html
|
31
|
-
#
|
32
|
-
#
|
33
|
-
# Ruby's Hash.invert method leaves a lot to wish for.. it can't handle the
|
34
|
-
# common case that two or more hash entries point to the same value..
|
35
|
-
#
|
36
|
-
# e.g.:
|
37
|
-
# h = {"ooh gott"=>3, "bla"=>3, "aua"=>3, "kotz"=>2, "blubb"=>9, "seier"=>3, "schigga"=>9}
|
38
|
-
# h.invert
|
39
|
-
# => {2=>"kotz", 3=>"seier", 9=>"schigga"}
|
40
|
-
#
|
41
|
-
# the above result IS SIMPLY WRONG!
|
42
|
-
#
|
43
|
-
# h.invert.invert
|
44
|
-
# => {"kotz"=>2, "seier"=>3, "schigga"=>9}
|
45
|
-
#
|
46
|
-
# h.invert.invert == h
|
47
|
-
# => false
|
48
|
-
#
|
49
|
-
# Let's conclude that Ruby's built-in Hash.invert method is REALLY BROKEN!
|
50
|
-
#
|
51
|
-
#
|
52
|
-
# OK, let's try this new inverse method:
|
53
|
-
#
|
54
|
-
# require 'invert_hash'
|
55
|
-
#
|
56
|
-
# h.inverse
|
57
|
-
# => {2=>"kotz", 3=>["seier", "aua", "bla", "ooh gott"], 9=>["schigga", "blubb"]}
|
58
|
-
#
|
59
|
-
# h.inverse.inverse
|
60
|
-
# => {"ooh gott"=>3, "bla"=>3, "aua"=>3, "kotz"=>2, "blubb"=>9, "seier"=>3, "schigga"=>9}
|
61
|
-
#
|
62
|
-
# h.inverse.inverse == h
|
63
|
-
# => true
|
64
|
-
#
|
65
|
-
# Looks much better, doesn't it?
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
class Hash
|
70
|
-
|
71
|
-
def inverse
|
72
|
-
i = Hash.new
|
73
|
-
self.each_pair{ |k,v|
|
74
|
-
if (v.class == Array)
|
75
|
-
v.each{ |x|
|
76
|
-
if i.has_key?(x)
|
77
|
-
i[x] = [k,i[x]].flatten
|
78
|
-
else
|
79
|
-
i[x] = k
|
80
|
-
end
|
81
|
-
}
|
82
|
-
else
|
83
|
-
if i.has_key?(v)
|
84
|
-
i[v] = [k,i[v]].flatten
|
85
|
-
else
|
86
|
-
i[v] = k
|
87
|
-
end
|
88
|
-
end
|
89
|
-
}
|
90
|
-
return i
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
__END__
|
96
|
-
|
97
|
-
# if you want to permanently overload Ruby's original invert method, you may want to do this:
|
98
|
-
|
99
|
-
class Hash
|
100
|
-
alias old_invert invert
|
101
|
-
|
102
|
-
def invert
|
103
|
-
self.inverse
|
104
|
-
end
|
105
|
-
end
|