{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
module Codec.Xlsx.Types.Internal.DvPair where
import qualified Data.Map as M
import GHC.Generics (Generic)
import Text.XML (Element(..))
import Codec.Xlsx.Parser.Internal
import Codec.Xlsx.Types.Common
import Codec.Xlsx.Types.DataValidation
import Codec.Xlsx.Writer.Internal
newtype DvPair = DvPair
{ DvPair -> (SqRef, DataValidation)
unDvPair :: (SqRef, DataValidation)
} deriving (DvPair -> DvPair -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DvPair -> DvPair -> Bool
$c/= :: DvPair -> DvPair -> Bool
== :: DvPair -> DvPair -> Bool
$c== :: DvPair -> DvPair -> Bool
Eq, Int -> DvPair -> ShowS
[DvPair] -> ShowS
DvPair -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DvPair] -> ShowS
$cshowList :: [DvPair] -> ShowS
show :: DvPair -> String
$cshow :: DvPair -> String
showsPrec :: Int -> DvPair -> ShowS
$cshowsPrec :: Int -> DvPair -> ShowS
Show, forall x. Rep DvPair x -> DvPair
forall x. DvPair -> Rep DvPair x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DvPair x -> DvPair
$cfrom :: forall x. DvPair -> Rep DvPair x
Generic)
instance FromCursor DvPair where
fromCursor :: Cursor -> [DvPair]
fromCursor Cursor
cur = do
SqRef
sqref <- forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"sqref" Cursor
cur
DataValidation
dv <- forall a. FromCursor a => Cursor -> [a]
fromCursor Cursor
cur
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ (SqRef, DataValidation) -> DvPair
DvPair (SqRef
sqref, DataValidation
dv)
instance FromXenoNode DvPair where
fromXenoNode :: Node -> Either Text DvPair
fromXenoNode Node
root = do
SqRef
sqref <- forall a. Node -> AttrParser a -> Either Text a
parseAttributes Node
root forall a b. (a -> b) -> a -> b
$ forall a. FromAttrBs a => ByteString -> AttrParser a
fromAttr ByteString
"sqref"
DataValidation
dv <- forall a. FromXenoNode a => Node -> Either Text a
fromXenoNode Node
root
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ (SqRef, DataValidation) -> DvPair
DvPair (SqRef
sqref, DataValidation
dv)
instance ToElement DvPair where
toElement :: Name -> DvPair -> Element
toElement Name
nm (DvPair (SqRef
sqRef,DataValidation
dv)) = Element
e
{elementAttributes :: Map Name Text
elementAttributes = forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Name
"sqref" (forall a. ToAttrVal a => a -> Text
toAttrVal SqRef
sqRef) forall a b. (a -> b) -> a -> b
$ Element -> Map Name Text
elementAttributes Element
e}
where
e :: Element
e = forall a. ToElement a => Name -> a -> Element
toElement Name
nm DataValidation
dv