Project.purs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. module LinkedIn.Profile.Project where
  2. import Prelude
  3. import Data.Either (Either, note)
  4. import Data.Foldable (findMap)
  5. import Data.Generic.Rep (class Generic)
  6. import Data.Maybe (Maybe(..))
  7. import Data.Show.Generic (genericShow)
  8. import LinkedIn (DetachedNode)
  9. import LinkedIn.ArtDecoCard (ArtDecoCardElement, toCenterContent, toHeaderBold, toHeaderNormal)
  10. import LinkedIn.Profile.Utils (maybeExtractFromMaybe, maybeGetInList, toUIElement)
  11. import LinkedIn.UIElements.Types (TimeSpan, 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 DetachedNode → Either String Project
  21. fromUI card = ado
  22. name <- note "No position found" $ findMap extractName bold
  23. in
  24. Project {
  25. name,
  26. timeSpan: maybeExtractFromMaybe extractTimeSpan normal,
  27. description: maybeGetInList extractDescription content 0
  28. }
  29. where
  30. asUI = toUIElement <$> card
  31. normal = toHeaderNormal asUI
  32. content = toCenterContent asUI
  33. bold = toHeaderBold asUI
  34. extractName :: UIElement -> Maybe String
  35. extractName = case _ of
  36. UIPlainText str -> Just str
  37. _ -> Nothing
  38. extractTimeSpan ∷ UIElement → Maybe TimeSpan
  39. extractTimeSpan = case _ of
  40. UITimeSpan s -> Just s
  41. UIDotSeparated (UITimeSpan s) _ -> Just s
  42. _ -> Nothing
  43. extractDescription ∷ UIElement → Maybe String
  44. extractDescription = case _ of
  45. UIPlainText d -> Just d
  46. _ -> Nothing