Project.purs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. module LinkedIn.Profile.Project where
  2. import Prelude
  3. import Data.Either (Either, note)
  4. import Data.Generic.Rep (class Generic)
  5. import Data.List as L
  6. import Data.Maybe (Maybe(..))
  7. import Data.Show.Generic (genericShow)
  8. import LinkedIn.UI.Components.ArtDecoCard (ArtDecoCardElement, toCenterContent, toHeaderBold, toHeaderNormal)
  9. import LinkedIn.UI.Basic.Types (TimeSpan)
  10. import LinkedIn.UI.Strings.Types (UIString(..))
  11. import LinkedIn.UI.Elements.Types (UIElement(..))
  12. data Project = Project {
  13. name :: String,
  14. timeSpan :: Maybe TimeSpan,
  15. description :: Maybe String
  16. }
  17. derive instance Generic Project _
  18. instance Show Project where
  19. show = genericShow
  20. fromUI ∷ ArtDecoCardElement UIElement → Either String Project
  21. fromUI card = ado
  22. name <- note "No position found" $ extractName bold
  23. in
  24. Project {
  25. name,
  26. timeSpan: extractTimeSpan =<< normal,
  27. description: extractDescription =<< L.index content 0
  28. }
  29. where
  30. normal = toHeaderNormal card
  31. content = toCenterContent card
  32. bold = toHeaderBold card
  33. extractName :: UIElement -> Maybe String
  34. extractName = case _ of
  35. UIElement (UIStringPlain str) -> Just str
  36. _ -> Nothing
  37. extractTimeSpan ∷ UIElement → Maybe TimeSpan
  38. extractTimeSpan = case _ of
  39. UIElement (UIStringTimeSpan s) -> Just s
  40. UIElement (UIStringDotSeparated (UIStringTimeSpan s) _) -> Just s
  41. _ -> Nothing
  42. extractDescription ∷ UIElement → Maybe String
  43. extractDescription = case _ of
  44. UIElement (UIStringPlain d) -> Just d
  45. _ -> Nothing