Class: Aqua::Translator::Rat
- Inherits:
-
Object
- Object
- Aqua::Translator::Rat
- Defined in:
- lib/aqua/object/translator.rb
Overview
Rat class is used by the translators packing side and aggregates methods for merging packed representation, externals and attachments
Instance Attribute Summary collapse
-
#attachments ⇒ Object
Returns the value of attribute attachments.
-
#externals ⇒ Object
Returns the value of attribute externals.
-
#pack ⇒ Object
Returns the value of attribute pack.
Instance Method Summary collapse
- #==(other_rat) ⇒ Object
-
#barf(accessor) ⇒ Object
outputs and resets the accessor.
-
#eat(other_rat) ⇒ Object
merges the two rats.
- #hord(other_rat, index) ⇒ Object
-
#initialize(pack = Mash.new, externals = Mash.new, attachments = []) ⇒ Rat
constructor
A new instance of Rat.
Constructor Details
#initialize(pack = Mash.new, externals = Mash.new, attachments = []) ⇒ Rat
Returns a new instance of Rat.
170 171 172 173 174 |
# File 'lib/aqua/object/translator.rb', line 170 def initialize( pack=Mash.new, externals=Mash.new, =[] ) self.pack = pack self.externals = externals self. = end |
Instance Attribute Details
#attachments ⇒ Object
Returns the value of attribute attachments.
169 170 171 |
# File 'lib/aqua/object/translator.rb', line 169 def end |
#externals ⇒ Object
Returns the value of attribute externals.
169 170 171 |
# File 'lib/aqua/object/translator.rb', line 169 def externals @externals end |
#pack ⇒ Object
Returns the value of attribute pack.
169 170 171 |
# File 'lib/aqua/object/translator.rb', line 169 def pack @pack end |
Instance Method Details
#==(other_rat) ⇒ Object
219 220 221 |
# File 'lib/aqua/object/translator.rb', line 219 def ==( other_rat ) self.pack == other_rat.pack && self.externals == other_rat.externals && self. == other_rat. end |
#barf(accessor) ⇒ Object
outputs and resets the accessor
189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/aqua/object/translator.rb', line 189 def ( accessor ) case accessor when :pack, 'pack' meal = self.pack self.pack = {} when :externals, 'externals' meal = self.externals self.externals = {} else meal = self. self. = [] end meal end |
#eat(other_rat) ⇒ Object
merges the two rats
177 178 179 180 181 182 183 184 185 186 |
# File 'lib/aqua/object/translator.rb', line 177 def eat( other_rat ) if self.pack.respond_to?(:keys) self.pack.merge!( other_rat.pack ) else self.pack << other_rat.pack # this is a special case for array init rats end self.externals.merge!( other_rat.externals ) self. += other_rat. self end |
#hord(other_rat, index) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/aqua/object/translator.rb', line 204 def hord( other_rat, index) if [String, Symbol].include?( index.class ) self.pack[index] = other_rat.(:pack) else # for nested hording eval_string = index.inject("self.pack") do |result, element| element = "'#{element}'" if element.class == String result += "[#{element}]" end value = other_rat.(:pack) instance_eval "#{eval_string} = #{value.inspect}" end self.eat( other_rat ) self end |