xbrlware-ruby19 1.1.2.19
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +4 -0
- data/Rakefile +2 -0
- data/lib/xbrlware-ruby19/cgi_patch.rb +58 -0
- data/lib/xbrlware-ruby19/constants.rb +29 -0
- data/lib/xbrlware-ruby19/context.rb +193 -0
- data/lib/xbrlware-ruby19/date_util.rb +45 -0
- data/lib/xbrlware-ruby19/float_patch.rb +26 -0
- data/lib/xbrlware-ruby19/hash_util.rb +175 -0
- data/lib/xbrlware-ruby19/instance.rb +475 -0
- data/lib/xbrlware-ruby19/item.rb +123 -0
- data/lib/xbrlware-ruby19/linkbase/calculation_linkbase.rb +181 -0
- data/lib/xbrlware-ruby19/linkbase/definition_linkbase.rb +226 -0
- data/lib/xbrlware-ruby19/linkbase/label_linkbase.rb +132 -0
- data/lib/xbrlware-ruby19/linkbase/linkbase.rb +193 -0
- data/lib/xbrlware-ruby19/linkbase/presentation_linkbase.rb +204 -0
- data/lib/xbrlware-ruby19/meta_util.rb +50 -0
- data/lib/xbrlware-ruby19/ns_aware.rb +5 -0
- data/lib/xbrlware-ruby19/taxonomies/ifrs_taxonomy_20090401.rb +8278 -0
- data/lib/xbrlware-ruby19/taxonomies/us_gaap_taxonomy_20090131.rb +40365 -0
- data/lib/xbrlware-ruby19/taxonomy.rb +143 -0
- data/lib/xbrlware-ruby19/unit.rb +43 -0
- data/lib/xbrlware-ruby19/util.rb +86 -0
- data/lib/xbrlware-ruby19/version.rb +22 -0
- data/lib/xbrlware-ruby19/xml_parser.rb +142 -0
- data/lib/xbrlware-ruby19.rb +73 -0
- data/xbrlware-ruby19.gemspec +27 -0
- metadata +109 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jim Lindstrom
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
# Xbrlware-ruby19
|
2
|
+
|
3
|
+
xbrlware-ruby19 is a re-packaging and ruby19-ification of <http://code.google.com/p/xbrlware/>, which describes itself as "a fast, lightweight framework for automation & analysis of XBRL." This repackaging carries the same Apache2.0 licensing as the original package.
|
4
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# This patch is to fix a bug in Ruby 1.8.x CGI::unescapeHTML
|
2
|
+
# Till we upgrade to Ruby 1.9, we will use this patch. Ruby 1.9 handles it properly.
|
3
|
+
# Other alternative is using htmlentities - http://htmlentities.rubyforge.org/
|
4
|
+
#
|
5
|
+
# Bug explanation,
|
6
|
+
# CGI::unescapeHTML("Equity in Earnings of") returns "Equity in Earnings\240of" instead of "Equity in Earnings of"
|
7
|
+
# CGI::unescapeHTML is not handling HTML numbers bigger than ~
|
8
|
+
#
|
9
|
+
# Fix explanation
|
10
|
+
# If HTML number is bigger than ~ treat them as   (32 is for space)
|
11
|
+
|
12
|
+
# below method copied from ruby-1.8.7-p248, ruby 1.8.7 (2009-12-24 patchlevel 248) for patching.
|
13
|
+
|
14
|
+
|
15
|
+
#class CGI
|
16
|
+
# # Unescape a string that has been HTML-escaped
|
17
|
+
# # CGI::unescapeHTML("Usage: foo "bar" <baz>")
|
18
|
+
# # # => "Usage: foo \"bar\" <baz>"
|
19
|
+
# def CGI::unescapeHTML(string)
|
20
|
+
# string.gsub(/&(amp|quot|gt|lt|\#[0-9]+|\#x[0-9A-Fa-f]+);/n) do
|
21
|
+
# match = $1.dup
|
22
|
+
# case match
|
23
|
+
# when 'amp' then
|
24
|
+
# '&'
|
25
|
+
# when 'quot' then
|
26
|
+
# '"'
|
27
|
+
# when 'gt' then
|
28
|
+
# '>'
|
29
|
+
# when 'lt' then
|
30
|
+
# '<'
|
31
|
+
# when /\A#0*(\d+)\z/n then
|
32
|
+
# if Integer($1) < 256
|
33
|
+
# 32.chr if Integer($1) > 126
|
34
|
+
# Integer($1).chr if Integer($1) <= 126
|
35
|
+
# else
|
36
|
+
# if Integer($1) < 65536 and ($KCODE[0] == ?u or $KCODE[0] == ?U)
|
37
|
+
# [Integer($1)].pack("U")
|
38
|
+
# else
|
39
|
+
# "&##{$1};"
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
# when /\A#x([0-9a-f]+)\z/ni then
|
43
|
+
# if $1.hex < 128
|
44
|
+
# $1.hex.chr
|
45
|
+
# else
|
46
|
+
# if $1.hex < 65536 and ($KCODE[0] == ?u or $KCODE[0] == ?U)
|
47
|
+
# [$1.hex].pack("U")
|
48
|
+
# else
|
49
|
+
# "&#x#{$1};"
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
# else
|
53
|
+
# "&#{match};"
|
54
|
+
# end
|
55
|
+
# end
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
#end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: xbrlware@bitstat.com
|
4
|
+
#
|
5
|
+
# Copyright:: 2009, 2010 bitstat (http://www.bitstat.com). All Rights Reserved.
|
6
|
+
#
|
7
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
16
|
+
# implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
module Xbrlware
|
21
|
+
# Linkbase constants
|
22
|
+
module LBConstants
|
23
|
+
CALCULATION="http://www.xbrl.org/2003/role/calculationLinkbaseRef"
|
24
|
+
DEFINITION="http://www.xbrl.org/2003/role/definitionLinkbaseRef"
|
25
|
+
PRESENTATION="http://www.xbrl.org/2003/role/presentationLinkbaseRef"
|
26
|
+
LABEL="http://www.xbrl.org/2003/role/labelLinkbaseRef"
|
27
|
+
REFERENCE="http://www.xbrl.org/2003/role/referenceLinkbaseRef"
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: xbrlware@bitstat.com
|
4
|
+
#
|
5
|
+
# Copyright:: 2009, 2010 bitstat (http://www.bitstat.com). All Rights Reserved.
|
6
|
+
#
|
7
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
16
|
+
# implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
module Xbrlware
|
21
|
+
# This class represents each context in the XBRL instance file.
|
22
|
+
# Look at {delaing with instance page on xbrlware wiki}[http://code.google.com/p/xbrlware/wiki/InstanceTaxonomy] for more details.
|
23
|
+
class Context
|
24
|
+
include NSAware
|
25
|
+
|
26
|
+
attr_reader :id, :entity, :period, :scenario
|
27
|
+
PERIOD_FOREVER = -1
|
28
|
+
|
29
|
+
class Period
|
30
|
+
attr_reader :value
|
31
|
+
|
32
|
+
def initialize(value)
|
33
|
+
@value = value
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
@value.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
def eql?(o)
|
41
|
+
o.is_a?(Period) && @value == o.value
|
42
|
+
end
|
43
|
+
|
44
|
+
def hash
|
45
|
+
@value.hash
|
46
|
+
end
|
47
|
+
|
48
|
+
def is_instant?
|
49
|
+
@value.is_a?(Date)
|
50
|
+
end
|
51
|
+
|
52
|
+
def is_duration?
|
53
|
+
@value.is_a?(Hash)
|
54
|
+
end
|
55
|
+
|
56
|
+
def is_forever?
|
57
|
+
@value.is_a?(Fixnum)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def initialize(id, entity, period, scenario=nil)
|
62
|
+
@id = id
|
63
|
+
@entity = entity
|
64
|
+
@period = Period.new(period)
|
65
|
+
@scenario=scenario
|
66
|
+
end
|
67
|
+
|
68
|
+
def has_scenario?
|
69
|
+
(not @scenario.nil?)
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_s
|
73
|
+
"Id [" + id + "], Entity { " + @entity.to_s + " }, period ["+period.to_s+"]"+ (", scenario ["+scenario+"]" unless scenario.nil?).to_s
|
74
|
+
end
|
75
|
+
|
76
|
+
def eql?(o)
|
77
|
+
o.is_a?(Context) && @id == o.id
|
78
|
+
end
|
79
|
+
|
80
|
+
def hash
|
81
|
+
@id.hash
|
82
|
+
end
|
83
|
+
|
84
|
+
def has_explicit_dimensions?(dimensions=[])
|
85
|
+
return @entity.has_explicit_dimensions?(dimensions) unless @entity.nil?
|
86
|
+
false
|
87
|
+
end
|
88
|
+
|
89
|
+
alias_method :has_dimensions?, :has_explicit_dimensions?
|
90
|
+
|
91
|
+
def explicit_dimensions
|
92
|
+
return @entity.explicit_dimensions
|
93
|
+
end
|
94
|
+
|
95
|
+
alias_method :dimensions, :explicit_dimensions
|
96
|
+
|
97
|
+
def explicit_domains(dimensions=[])
|
98
|
+
return @entity.explicit_domains(dimensions)
|
99
|
+
end
|
100
|
+
|
101
|
+
alias_method :domains, :explicit_domains
|
102
|
+
|
103
|
+
def explicit_dimensions_domains
|
104
|
+
return @entity.explicit_dimensions_domains
|
105
|
+
end
|
106
|
+
|
107
|
+
alias_method :dimensions_domains, :explicit_dimensions_domains
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
class Entity
|
112
|
+
attr_reader :identifier, :segment
|
113
|
+
|
114
|
+
def initialize(identifier, segment=nil)
|
115
|
+
@identifier = identifier
|
116
|
+
@segment = segment
|
117
|
+
end
|
118
|
+
|
119
|
+
def has_segment?
|
120
|
+
(not @segment.nil?)
|
121
|
+
end
|
122
|
+
|
123
|
+
def to_s
|
124
|
+
"Identifier { " + @identifier.to_s + " } " + (", segment [" + segment.to_s + "]" unless segment.nil?).to_s
|
125
|
+
end
|
126
|
+
|
127
|
+
def has_explicit_dimensions?(dimensions=[])
|
128
|
+
dimensions_set=Set.new
|
129
|
+
dimensions_set.merge(dimensions)
|
130
|
+
unless @segment.nil? || @segment["explicitMember"].nil?
|
131
|
+
|
132
|
+
return true if dimensions.size==0
|
133
|
+
|
134
|
+
dim = Set.new
|
135
|
+
@segment["explicitMember"].each do |member|
|
136
|
+
dim << member["dimension"]
|
137
|
+
end
|
138
|
+
return dim.superset?(dimensions_set)
|
139
|
+
end
|
140
|
+
|
141
|
+
return false
|
142
|
+
end
|
143
|
+
|
144
|
+
def explicit_dimensions
|
145
|
+
dim = Set.new
|
146
|
+
unless @segment.nil? || @segment["explicitMember"].nil?
|
147
|
+
@segment["explicitMember"].each do |member|
|
148
|
+
dim << member["dimension"]
|
149
|
+
end
|
150
|
+
end
|
151
|
+
return dim.to_a
|
152
|
+
end
|
153
|
+
|
154
|
+
def explicit_domains(dimensions=[])
|
155
|
+
dom = Set.new
|
156
|
+
if has_explicit_dimensions?(dimensions)
|
157
|
+
@segment["explicitMember"].each do |member|
|
158
|
+
dimensions=explicit_dimensions if dimensions.size==0
|
159
|
+
dimensions.each do |dim|
|
160
|
+
next unless dim==member["dimension"]
|
161
|
+
dom << member["content"]
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
return dom.to_a
|
166
|
+
end
|
167
|
+
|
168
|
+
def explicit_dimensions_domains
|
169
|
+
dim_dom={}
|
170
|
+
if has_explicit_dimensions?
|
171
|
+
@segment["explicitMember"].each do |member|
|
172
|
+
dim_dom[member["dimension"]]=[] if dim_dom[member["dimension"]].nil?
|
173
|
+
dim_dom[member["dimension"]] << member["content"]
|
174
|
+
end
|
175
|
+
end
|
176
|
+
return dim_dom
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
class Identifier
|
182
|
+
attr_reader :value, :scheme
|
183
|
+
|
184
|
+
def initialize(scheme, value)
|
185
|
+
@scheme = scheme
|
186
|
+
@value = value
|
187
|
+
end
|
188
|
+
|
189
|
+
def to_s
|
190
|
+
"schema [" + @scheme.to_s + "], value [" + @value.to_s + "]"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: xbrlware@bitstat.com
|
4
|
+
#
|
5
|
+
# Copyright:: 2009, 2010 bitstat (http://www.bitstat.com). All Rights Reserved.
|
6
|
+
#
|
7
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
16
|
+
# implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
module Xbrlware
|
21
|
+
module DateUtil # :nodoc:
|
22
|
+
def self.stringify_date (date)
|
23
|
+
return "" if date.nil?
|
24
|
+
begin
|
25
|
+
_date=Date.parse(date) if date.is_a?(String)
|
26
|
+
_date=date if date.is_a?(Date)
|
27
|
+
m=Date::ABBR_MONTHNAMES[_date.month]
|
28
|
+
m + " " + _date.day.to_s + ", " + _date.year.to_s
|
29
|
+
rescue Exception => e
|
30
|
+
""
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.months_between(date1=Date.today, date2=Date.today)
|
35
|
+
begin
|
36
|
+
date1=Date.parse(date1) if date1.is_a?(String)
|
37
|
+
date2=Date.parse(date2) if date2.is_a?(String)
|
38
|
+
(date1 > date2) ? (recent_date, past_date = date1, date2) : (recent_date, past_date = date2, date1)
|
39
|
+
(recent_date.year - past_date.year) * 12 + (recent_date.month - past_date.month) + 1
|
40
|
+
rescue Exception => e
|
41
|
+
0
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: xbrlware@bitstat.com
|
4
|
+
#
|
5
|
+
# Copyright:: 2009, 2010 bitstat (http://www.bitstat.com). All Rights Reserved.
|
6
|
+
#
|
7
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
16
|
+
# implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
class Float # :nodoc:
|
21
|
+
def round_at(precision)
|
22
|
+
(self * (10 ** precision)).round.to_f / 10 ** precision
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
@@ -0,0 +1,175 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: xbrlware@bitstat.com
|
4
|
+
#
|
5
|
+
# Copyright:: 2009, 2010 bitstat (http://www.bitstat.com). All Rights Reserved.
|
6
|
+
#
|
7
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
16
|
+
# implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
module Xbrlware
|
21
|
+
module HashUtil # :nodoc:
|
22
|
+
def self.to_obj(hash)
|
23
|
+
o = Object.new()
|
24
|
+
hash.each do |k, v|
|
25
|
+
v=self.to_obj(v) if v.is_a?(Hash)
|
26
|
+
MetaUtil::introduce_instance_var(o, k, v)
|
27
|
+
end
|
28
|
+
return o
|
29
|
+
end
|
30
|
+
|
31
|
+
# In Ruby 1.9, the Hash is ordered by default.
|
32
|
+
if RUBY_VERSION >= '1.9'
|
33
|
+
OHash = ::Hash
|
34
|
+
else
|
35
|
+
class OHash < Hash #:nodoc:
|
36
|
+
def initialize(*args, &block)
|
37
|
+
super
|
38
|
+
@keys = []
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.[](*args)
|
42
|
+
ordered_hash = new
|
43
|
+
|
44
|
+
if (args.length == 1 && args.first.is_a?(Array))
|
45
|
+
args.first.each do |key_value_pair|
|
46
|
+
next unless (key_value_pair.is_a?(Array))
|
47
|
+
ordered_hash[key_value_pair[0]] = key_value_pair[1]
|
48
|
+
end
|
49
|
+
|
50
|
+
return ordered_hash
|
51
|
+
end
|
52
|
+
|
53
|
+
unless (args.size % 2 == 0)
|
54
|
+
raise ArgumentError.new("odd number of arguments for Hash")
|
55
|
+
end
|
56
|
+
|
57
|
+
args.each_with_index do |val, ind|
|
58
|
+
next if (ind % 2 != 0)
|
59
|
+
ordered_hash[val] = args[ind + 1]
|
60
|
+
end
|
61
|
+
|
62
|
+
ordered_hash
|
63
|
+
end
|
64
|
+
|
65
|
+
def initialize_copy(other)
|
66
|
+
super
|
67
|
+
# make a deep copy of keys
|
68
|
+
@keys = other.keys
|
69
|
+
end
|
70
|
+
|
71
|
+
def []=(key, value)
|
72
|
+
@keys << key if !has_key?(key)
|
73
|
+
super
|
74
|
+
end
|
75
|
+
|
76
|
+
def keys
|
77
|
+
@keys.dup
|
78
|
+
end
|
79
|
+
|
80
|
+
def values
|
81
|
+
@keys.collect { |key| self[key] }
|
82
|
+
end
|
83
|
+
|
84
|
+
def delete(key)
|
85
|
+
if has_key? key
|
86
|
+
index = @keys.index(key)
|
87
|
+
@keys.delete_at index
|
88
|
+
end
|
89
|
+
super
|
90
|
+
end
|
91
|
+
|
92
|
+
def delete_if
|
93
|
+
super
|
94
|
+
sync_keys!
|
95
|
+
self
|
96
|
+
end
|
97
|
+
|
98
|
+
def reject!
|
99
|
+
super
|
100
|
+
sync_keys!
|
101
|
+
self
|
102
|
+
end
|
103
|
+
|
104
|
+
def reject(&block)
|
105
|
+
dup.reject!(&block)
|
106
|
+
end
|
107
|
+
|
108
|
+
def to_hash
|
109
|
+
self
|
110
|
+
end
|
111
|
+
|
112
|
+
def to_a
|
113
|
+
@keys.map { |key| [ key, self[key] ] }
|
114
|
+
end
|
115
|
+
|
116
|
+
def each_key
|
117
|
+
@keys.each { |key| yield key }
|
118
|
+
end
|
119
|
+
|
120
|
+
def each_value
|
121
|
+
@keys.each { |key| yield self[key]}
|
122
|
+
end
|
123
|
+
|
124
|
+
def each
|
125
|
+
@keys.each {|key| yield [key, self[key]]}
|
126
|
+
end
|
127
|
+
|
128
|
+
alias_method :each_pair, :each
|
129
|
+
|
130
|
+
def clear
|
131
|
+
super
|
132
|
+
@keys.clear
|
133
|
+
self
|
134
|
+
end
|
135
|
+
|
136
|
+
def shift
|
137
|
+
k = @keys.first
|
138
|
+
v = delete(k)
|
139
|
+
[k, v]
|
140
|
+
end
|
141
|
+
|
142
|
+
def merge!(other_hash)
|
143
|
+
other_hash.each {|k, v| self[k] = v }
|
144
|
+
self
|
145
|
+
end
|
146
|
+
|
147
|
+
def merge(other_hash)
|
148
|
+
dup.merge!(other_hash)
|
149
|
+
end
|
150
|
+
|
151
|
+
# replace with keys from other Hash. The other Hash could be ordered or not ordered.
|
152
|
+
def replace(other)
|
153
|
+
super
|
154
|
+
@keys = other.keys
|
155
|
+
self
|
156
|
+
end
|
157
|
+
|
158
|
+
def inspect
|
159
|
+
"#<OHash #{super}>"
|
160
|
+
end
|
161
|
+
|
162
|
+
# XmlSimple's export to xml from Hash depends on instance_of?(Hash)
|
163
|
+
def instance_of?(clazz)
|
164
|
+
self.is_a?(clazz)
|
165
|
+
end
|
166
|
+
|
167
|
+
private
|
168
|
+
|
169
|
+
def sync_keys!
|
170
|
+
@keys.delete_if {|k| !has_key?(k)}
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|