Explorar o código

Replace global toUI with functions named e.g. toHeaderNormal

jherve hai 1 ano
pai
achega
6976ef2cb1

+ 20 - 28
src/LinkedIn/ArtDeco.purs

@@ -104,32 +104,24 @@ parseArtDecoPvsEntity n = do
     c <- center
   in ArtDecoPvsEntity {side: unit, center: c}
 
-toUI ∷
-  ArtDecoPvsEntity
-  → {
-    bold' ∷ Either ParseError UIElement ,
-    content' ∷ List (Either ParseError UIElement) ,
-    light' ∷ Maybe (NonEmptyList (Either ParseError UIElement)) ,
-    normal' ∷ Maybe (Either ParseError UIElement)
+toHeaderBold ∷ ArtDecoPvsEntity → Either ParseError UIElement
+toHeaderBold (ArtDecoPvsEntity {
+    center: ArtDecoCenter { header: ArtDecoCenterHeader { bold }
   }
-toUI (ArtDecoPvsEntity {
-    center: ArtDecoCenter {
-      header: ArtDecoCenterHeader {
-        bold,
-        normal,
-        light
-      },
-      content: ArtDecoCenterContent subComponents
-    }
-  }) = {bold', content', normal', light'} where
-  bold' = toUIElement bold
-
-  content' :: List (Either ParseError UIElement)
-  content' = map toUIElement subC
-    where subC = NEL.catMaybes $ map (\(ArtDecoPvsEntitySubComponent c) -> c) subComponents :: List (DetachedNode)
-
-  normal' :: Maybe (Either ParseError UIElement)
-  normal' = toUIElement <$> normal
-
-  light' :: Maybe (NonEmptyList (Either ParseError UIElement))
-  light' = (map toUIElement) <$> light
+}) = toUIElement bold
+
+toHeaderNormal ∷ ArtDecoPvsEntity → Maybe (Either ParseError UIElement)
+toHeaderNormal (ArtDecoPvsEntity {
+  center: ArtDecoCenter { header: ArtDecoCenterHeader { normal }}
+}) = toUIElement <$> normal
+
+toHeaderLight ∷ ArtDecoPvsEntity → Maybe (NonEmptyList (Either ParseError UIElement))
+toHeaderLight (ArtDecoPvsEntity {
+  center: ArtDecoCenter { header: ArtDecoCenterHeader { light } }
+}) = (map toUIElement) <$> light
+
+toCenterContent ∷ ArtDecoPvsEntity → List (Either ParseError UIElement)
+toCenterContent (ArtDecoPvsEntity {
+  center: ArtDecoCenter { content: ArtDecoCenterContent subComponents }
+}) = map toUIElement subC
+  where subC = NEL.catMaybes $ map (\(ArtDecoPvsEntitySubComponent c) -> c) subComponents :: List (DetachedNode)

+ 22 - 3
src/LinkedIn/ArtDecoCard.purs

@@ -2,12 +2,18 @@ module LinkedIn.ArtDecoCard where
 
 import Prelude
 
+import Data.Either (Either)
 import Data.Generic.Rep (class Generic)
+import Data.List (List)
+import Data.List.Types (NonEmptyList)
+import Data.Maybe (Maybe)
 import Data.Show.Generic (genericShow)
-import LinkedIn.Types (Parser)
-import LinkedIn.Utils (queryOneAndParse)
 import LinkedIn.ArtDeco (ArtDecoPvsEntity, parseArtDecoPvsEntity)
 import LinkedIn.ArtDeco as AD
+import LinkedIn.Types (Parser)
+import LinkedIn.UIElements.Types (UIElement)
+import LinkedIn.Utils (queryOneAndParse)
+import Parsing (ParseError)
 
 
 data ArtDecoCardElement = ArtDecoCardElement {
@@ -27,4 +33,17 @@ parseArtDecoCard n = do
     p <- pvs
   in ArtDecoCardElement {pvs_entity: p}
 
-toUI (ArtDecoCardElement { pvs_entity}) = AD.toUI pvs_entity
+toCenterContent ∷ ArtDecoCardElement → List (Either ParseError UIElement)
+toCenterContent = toPvsEntity >>> AD.toCenterContent
+
+toHeaderBold ∷ ArtDecoCardElement → Either ParseError UIElement
+toHeaderBold = toPvsEntity >>> AD.toHeaderBold
+
+toHeaderLight ∷ ArtDecoCardElement → Maybe (NonEmptyList (Either ParseError UIElement))
+toHeaderLight = toPvsEntity >>> AD.toHeaderLight
+
+toHeaderNormal ∷ ArtDecoCardElement → Maybe (Either ParseError UIElement)
+toHeaderNormal = toPvsEntity >>> AD.toHeaderNormal
+
+toPvsEntity ∷ ArtDecoCardElement → ArtDecoPvsEntity
+toPvsEntity (ArtDecoCardElement { pvs_entity }) = pvs_entity

+ 20 - 1
src/LinkedIn/ArtDecoTab.purs

@@ -2,12 +2,18 @@ module LinkedIn.ArtDecoTab where
 
 import Prelude
 
+import Data.Either (Either)
 import Data.Generic.Rep (class Generic)
+import Data.List (List)
+import Data.List.Types (NonEmptyList)
+import Data.Maybe (Maybe)
 import Data.Show.Generic (genericShow)
 import LinkedIn.Types (Parser)
 import LinkedIn.Utils (queryOneAndParse)
+import LinkedIn.UIElements.Types (UIElement)
 import LinkedIn.ArtDeco (ArtDecoPvsEntity, parseArtDecoPvsEntity)
 import LinkedIn.ArtDeco as AD
+import Parsing (ParseError)
 
 
 data ArtDecoTabElement = ArtDecoTabElement {
@@ -27,4 +33,17 @@ parseArtDecoTab n = do
     p <- pvs
   in ArtDecoTabElement {pvs_entity: p}
 
-toUI (ArtDecoTabElement { pvs_entity }) = AD.toUI pvs_entity
+toCenterContent ∷ ArtDecoTabElement → List (Either ParseError UIElement)
+toCenterContent = toPvsEntity >>> AD.toCenterContent
+
+toHeaderBold ∷ ArtDecoTabElement → Either ParseError UIElement
+toHeaderBold = toPvsEntity >>> AD.toHeaderBold
+
+toHeaderLight ∷ ArtDecoTabElement → Maybe (NonEmptyList (Either ParseError UIElement))
+toHeaderLight = toPvsEntity >>> AD.toHeaderLight
+
+toHeaderNormal ∷ ArtDecoTabElement → Maybe (Either ParseError UIElement)
+toHeaderNormal = toPvsEntity >>> AD.toHeaderNormal
+
+toPvsEntity ∷ ArtDecoTabElement → ArtDecoPvsEntity
+toPvsEntity (ArtDecoTabElement { pvs_entity }) = pvs_entity

+ 8 - 7
src/LinkedIn/Profile/Project.purs

@@ -1,7 +1,5 @@
 module LinkedIn.Profile.Project where
 
-import LinkedIn.Profile.Utils
-import LinkedIn.UIElements.Parser
 import Prelude
 
 import Data.Either (Either, note)
@@ -9,7 +7,8 @@ import Data.Foldable (findMap)
 import Data.Generic.Rep (class Generic)
 import Data.Maybe (Maybe(..))
 import Data.Show.Generic (genericShow)
-import LinkedIn.ArtDecoCard (ArtDecoCardElement, toUI)
+import LinkedIn.Profile.Utils (maybeExtractFromMaybe, maybeGetInList)
+import LinkedIn.ArtDecoCard (ArtDecoCardElement,  toCenterContent, toHeaderBold, toHeaderNormal)
 import LinkedIn.UIElements.Types (TimeSpan, UIElement(..))
 
 data Project = Project {
@@ -24,15 +23,17 @@ instance Show Project where
 
 fromUI ∷ ArtDecoCardElement → Either String Project
 fromUI card = ado
-    name <- note "No position found" $ findMap extractName bold'
+    name <- note "No position found" $ findMap extractName bold
   in
     Project {
     name,
-    timeSpan: maybeExtractFromMaybe extractTimeSpan normal',
-    description: maybeGetInList extractDescription content' 0
+    timeSpan: maybeExtractFromMaybe extractTimeSpan normal,
+    description: maybeGetInList extractDescription content 0
   }
   where
-    {bold', content', normal'} = toUI card
+    normal = toHeaderNormal card
+    content = toCenterContent card
+    bold = toHeaderBold card
 
 extractName :: UIElement -> Maybe String
 extractName = case _ of

+ 3 - 5
src/LinkedIn/Profile/Skill.purs

@@ -1,7 +1,5 @@
 module LinkedIn.Profile.Skill where
 
-import LinkedIn.Profile.Utils
-import LinkedIn.UIElements.Parser
 import Prelude
 
 import Data.Either (Either, note)
@@ -9,7 +7,7 @@ import Data.Foldable (findMap)
 import Data.Generic.Rep (class Generic)
 import Data.Maybe (Maybe(..))
 import Data.Show.Generic (genericShow)
-import LinkedIn.ArtDecoTab (ArtDecoTabElement, toUI)
+import LinkedIn.ArtDecoTab (ArtDecoTabElement, toHeaderBold)
 import LinkedIn.UIElements.Types (UIElement(..))
 
 data Skill = Skill {
@@ -22,11 +20,11 @@ instance Show Skill where
 
 fromUI ∷ ArtDecoTabElement → Either String Skill
 fromUI (tab) = ado
-    name <- note "No position found" $ findMap extractName bold'
+    name <- note "No position found" $ findMap extractName bold
   in
     Skill { name }
   where
-    {bold'} = toUI tab
+    bold = toHeaderBold tab
 
 extractName :: UIElement -> Maybe String
 extractName = case _ of

+ 12 - 10
src/LinkedIn/Profile/WorkExperience.purs

@@ -1,7 +1,5 @@
 module LinkedIn.Profile.WorkExperience where
 
-import LinkedIn.Profile.Utils
-import LinkedIn.UIElements.Parser
 import Prelude
 
 import Data.Either (Either, note)
@@ -9,7 +7,8 @@ import Data.Foldable (findMap)
 import Data.Generic.Rep (class Generic)
 import Data.Maybe (Maybe(..))
 import Data.Show.Generic (genericShow)
-import LinkedIn.ArtDecoCard (ArtDecoCardElement, toUI)
+import LinkedIn.ArtDecoCard (ArtDecoCardElement, toCenterContent, toHeaderBold, toHeaderLight, toHeaderNormal)
+import LinkedIn.Profile.Utils (maybeExtractFromMaybe, maybeFindInMaybeNEL, maybeGetInList)
 import LinkedIn.UIElements.Types (Duration, TimeSpan, UIElement(..))
 
 data WorkExperience = WorkExperience {
@@ -28,18 +27,21 @@ instance Show WorkExperience where
 
 fromUI ∷ ArtDecoCardElement → Either String WorkExperience
 fromUI (card) = ado
-    position <- note "No position found" $ findMap extractPosition bold'
+    position <- note "No position found" $ findMap extractPosition bold
   in
     WorkExperience {
     position,
-    company: maybeExtractFromMaybe extractCompany normal',
-    contractType: maybeExtractFromMaybe extractContractType normal',
-    timeSpan: maybeFindInMaybeNEL extractTimeSpan light',
-    duration: maybeFindInMaybeNEL extractDuration light',
-    description: maybeGetInList extractDescription content' 0
+    company: maybeExtractFromMaybe extractCompany normal,
+    contractType: maybeExtractFromMaybe extractContractType normal,
+    timeSpan: maybeFindInMaybeNEL extractTimeSpan light,
+    duration: maybeFindInMaybeNEL extractDuration light,
+    description: maybeGetInList extractDescription content 0
   }
   where
-    {bold', content', normal', light'} = toUI card
+    normal = toHeaderNormal card
+    light = toHeaderLight card
+    content = toCenterContent card
+    bold = toHeaderBold card
 
 extractPosition :: UIElement -> Maybe String
 extractPosition = case _ of