WorkExperience.purs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. module LinkedIn.Profile.WorkExperience where
  2. import LinkedIn.UIElements.Parser
  3. import Prelude
  4. import Data.Either (Either, note)
  5. import Data.Foldable (findMap)
  6. import Data.Generic.Rep (class Generic)
  7. import Data.List (List)
  8. import Data.List.NonEmpty (NonEmptyList)
  9. import Data.List.NonEmpty as NEL
  10. import Data.Maybe (Maybe(..))
  11. import Data.Show.Generic (genericShow)
  12. import LinkedIn (DetachedNode)
  13. import LinkedIn.ArtDecoCard (ArtDecoCardElement(..), ArtDecoCenter(..), ArtDecoCenterContent(..), ArtDecoCenterHeader(..), ArtDecoPvsEntity(..), ArtDecoPvsEntitySubComponent(..))
  14. import LinkedIn.UIElements.Types (Duration, TimeSpan, UIElement(..))
  15. import LinkedIn.Profile.Utils
  16. import Parsing (ParseError)
  17. data WorkExperience = WorkExperience {
  18. position :: String,
  19. company :: Maybe String,
  20. contractType :: Maybe String,
  21. timeSpan :: Maybe TimeSpan,
  22. duration :: Maybe Duration,
  23. description :: Maybe String
  24. }
  25. derive instance Generic WorkExperience _
  26. instance Show WorkExperience where
  27. show = genericShow
  28. fromUI ∷ ArtDecoCardElement → Either String WorkExperience
  29. fromUI (ArtDecoCardElement {
  30. pvs_entity: ArtDecoPvsEntity {
  31. center: ArtDecoCenter {
  32. header: ArtDecoCenterHeader {
  33. bold,
  34. normal,
  35. light
  36. },
  37. content: ArtDecoCenterContent subComponents
  38. }
  39. }
  40. }) = ado
  41. position <- note "No position found" $ findMap extractPosition bold'
  42. in
  43. WorkExperience {
  44. position,
  45. company: maybeExtractFromMaybe extractCompany normal',
  46. contractType: maybeExtractFromMaybe extractContractType normal',
  47. timeSpan: maybeFindInMaybeNEL extractTimeSpan light',
  48. duration: maybeFindInMaybeNEL extractDuration light',
  49. description: maybeGetInList extractDescription content' 0
  50. } where
  51. bold' = toUIElement bold
  52. content' :: List (Either ParseError UIElement)
  53. content' = map toUIElement subC
  54. where subC = NEL.catMaybes $ map (\(ArtDecoPvsEntitySubComponent c) -> c) subComponents :: List (DetachedNode)
  55. normal' :: Maybe (Either ParseError UIElement)
  56. normal' = toUIElement <$> normal
  57. light' :: Maybe (NonEmptyList (Either ParseError UIElement))
  58. light' = (map toUIElement) <$> light
  59. extractPosition :: UIElement -> Maybe String
  60. extractPosition = case _ of
  61. UIPlainText str -> Just str
  62. _ -> Nothing
  63. extractCompany ∷ UIElement → Maybe String
  64. extractCompany = case _ of
  65. UIPlainText str -> Just str
  66. UIDotSeparated (UIPlainText str) _ -> Just str
  67. _ -> Nothing
  68. extractContractType ∷ UIElement → Maybe String
  69. extractContractType = case _ of
  70. UIDotSeparated _ (UIPlainText str) -> Just str
  71. _ -> Nothing
  72. extractTimeSpan ∷ UIElement → Maybe TimeSpan
  73. extractTimeSpan = case _ of
  74. UIDotSeparated (UITimeSpan s) _ -> Just s
  75. _ -> Nothing
  76. extractDuration ∷ UIElement → Maybe Duration
  77. extractDuration = case _ of
  78. UIDotSeparated _ (UIDuration d) -> Just d
  79. _ -> Nothing
  80. extractDescription ∷ UIElement → Maybe String
  81. extractDescription = case _ of
  82. UIPlainText d -> Just d
  83. _ -> Nothing