Skip to content

Instantly share code, notes, and snippets.

@schrepfler
Created January 23, 2016 17:15
Show Gist options
  • Save schrepfler/b4c7dbec18dcc02ea861 to your computer and use it in GitHub Desktop.
Save schrepfler/b4c7dbec18dcc02ea861 to your computer and use it in GitHub Desktop.
class CapabilitiesExtractor(val device: Device, val capabilitiesFilter: Option[List[String]]) {
def extract(): Map[String, Option[CapabilityValue]] = {
val capabilities = device.capabilities ++ device.virtualCapabilities
???
}
}
object CapabilitiesExtractor {
val typeMap = Map[String, (Option[String]) => Option[CapabilityValue]](
"mobile_browser" -> stringToString,
"nokia_feature_pack" -> stringToNumeric,
"has_qwerty_keyboard" -> stringToBoolean,
...
)
def stringToNumeric(value: Option[String]): Option[CapabilityValue] = {
Some(IntValue(Try(value.get.toInt).getOrElse(return None)))
}
def stringToBoolean(value: Option[String]): Option[CapabilityValue] = {
Some(BoolValue(Try(value.get.toBoolean).getOrElse(return None)))
}
def stringToString(value: Option[String]): Option[CapabilityValue] = {
Some(StringValue(value.get))
}
def remap(key: String, value: Option[String]): Option[CapabilityValue] = {
return typeMap.get(key).get(value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment