Created
January 23, 2016 17:15
-
-
Save schrepfler/b4c7dbec18dcc02ea861 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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