module AlBhed
( -- * Classes
Primer (..)
, Volume (..)
-- * Conversions
, fromVolume
, toRoman
, toVolume
) where
import Data.List
import Data.Maybe
import qualified Data.Text as T
data Volume
= One
| Two
| Three
| Four
| Five
| Six
| Seven
| Eight
| Nine
| Ten
| Eleven
| Twelve
| Thirteen
| Fourteen
| Fifteen
| Sixteen
| Seventeen
| Eigthteen
| Nineteen
| Twenty
| TwentyOne
| TwentyTwo
| TwentyThree
| TwentyFour
| TwentyFive
| TwentySix
deriving (Enum, Bounded)
data Primer = Primer
{ primerVolume :: Volume
, primerEnglish :: Char
, primerAlBhed :: Char
}
toVolume :: Int -> Maybe Volume
toVolume x
| x >= 1 && x <= 26 = Just $ toEnum (x - 1)
| otherwise = Nothing
fromVolume :: Volume -> Int
fromVolume = fromEnum
toRoman :: Volume -> T.Text
toRoman x = T.pack $ go (fromEnum x + 1)
where
go 0 = []
go x =
let (break, roman) = fromMaybe undefined (findClosestRoman x)
in roman ++ go (x - break)
romanSymbols :: [(Int, String)]
romanSymbols =
[ (10, "X")
, (9, "IX")
, (5, "V")
, (4, "IV")
, (1, "I")
]
findClosestRoman :: Int -> Maybe (Int, String)
findClosestRoman x = find ((x >=) . fst) romanSymbols