Class: PMHashBundle
- Defined in:
- lib/project/pro_motion/support/pm_hash_bundle.rb
Constant Summary collapse
- KEYS_KEY =
"pm_hash_bundle_hash_keys"
- VALUE_TYPES_KEY =
"pm_hash_bundle_value_types"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(bundle, hash) ⇒ PMHashBundle
constructor
A new instance of PMHashBundle.
- #to_bundle ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(bundle, hash) ⇒ PMHashBundle
5 6 7 8 |
# File 'lib/project/pro_motion/support/pm_hash_bundle.rb', line 5 def initialize(bundle, hash) @bundle = bundle @hash = hash end |
Class Method Details
.from_bundle(bundle) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/project/pro_motion/support/pm_hash_bundle.rb', line 20 def from_bundle(bundle) #hash_keys = fragment_arguments.getStringArrayList("hash_keys") h = {} keys = bundle.getStringArrayList(PMHashBundle::KEYS_KEY) value_types = bundle.getStringArrayList(PMHashBundle::VALUE_TYPES_KEY) keys.each_with_index do |key, i| value_type = value_types[i] value = case value_type when "com.rubymotion.String" bundle.getString(key) when "com.rubymotion.Symbol" bundle.getString(key).to_sym when "java.lang.Integer" bundle.getInt(key) when "java.lang.Double" bundle.getFloat(key) when "java.util.ArrayList" bundle.getStringArrayList(key) # TODO, do more types else raise "[BluePotion ERROR] In PMHashBundle#from_hash: invalid type for: #{key}" end h[key.to_sym] = value end PMHashBundle.new(bundle, h) end |
.from_hash(h) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/project/pro_motion/support/pm_hash_bundle.rb', line 52 def from_hash(h) bundle = Potion::Bundle.new keys = h.keys.map(&:to_s) values = h.values value_types = h.values.map do |value| value.class.name end bundle.putStringArrayList(PMHashBundle::KEYS_KEY, keys) bundle.putStringArrayList(PMHashBundle::VALUE_TYPES_KEY, value_types) keys.each_with_index do |key, i| value_type = value_types[i] value = values[i] case value_type when "com.rubymotion.String" bundle.putString(key, value) when "com.rubymotion.Symbol" bundle.putString(key, value.to_s) when "java.lang.Integer" bundle.putInt(key, value) when "java.lang.Double" bundle.putFloat(key, value) when "java.util.ArrayList" value = value.map{|o| o.to_s} bundle.putStringArrayList(key, value) # TODO, do more types else raise "[BluePotion ERROR] In PMHashBundle#from_hash: invalid type for: #{key}" end end PMHashBundle.new(bundle, h) end |