Project.purs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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.ArtDecoCard (ArtDecoCardElement, toCenterContent, toHeaderBold, toHeaderNormal)
  9. import LinkedIn.UIElements.Types (TimeSpan, UIElement(..), UIString(..))
  10. data Project = Project {
  11. name :: String,
  12. timeSpan :: Maybe TimeSpan,
  13. description :: Maybe String
  14. }
  15. derive instance Generic Project _
  16. instance Show Project where
  17. show = genericShow
  18. fromUI ∷ ArtDecoCardElement UIElement → Either String Project
  19. fromUI card = ado
  20. name <- note "No position found" $ extractName bold
  21. in
  22. Project {
  23. name,
  24. timeSpan: extractTimeSpan =<< normal,
  25. description: extractDescription =<< L.index content 0
  26. }
  27. where
  28. normal = toHeaderNormal card
  29. content = toCenterContent card
  30. bold = toHeaderBold card
  31. extractName :: UIElement -> Maybe String
  32. extractName = case _ of
  33. UIElement (UIStringPlain str) -> Just str
  34. _ -> Nothing
  35. extractTimeSpan ∷ UIElement → Maybe TimeSpan
  36. extractTimeSpan = case _ of
  37. UIElement (UIStringTimeSpan s) -> Just s
  38. UIElement (UIStringDotSeparated (UIStringTimeSpan s) _) -> Just s
  39. _ -> Nothing
  40. extractDescription ∷ UIElement → Maybe String
  41. extractDescription = case _ of
  42. UIElement (UIStringPlain d) -> Just d
  43. _ -> Nothing