class PMHashBundle

Constants

KEYS_KEY
VALUE_TYPES_KEY

Public Class Methods

from_bundle(bundle) click to toggle source
# 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) click to toggle source
# 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
new(bundle, hash) click to toggle source
# File lib/project/pro_motion/support/pm_hash_bundle.rb, line 5
def initialize(bundle, hash)
  @bundle = bundle
  @hash = hash
end

Public Instance Methods

to_bundle() click to toggle source
# File lib/project/pro_motion/support/pm_hash_bundle.rb, line 10
def to_bundle
  @bundle
end
to_h() click to toggle source
# File lib/project/pro_motion/support/pm_hash_bundle.rb, line 14
def to_h
  @hash
end