Merge pull request #49 from mtlstats/auto-capitalize
Auto capitalize player/goalie names
This commit is contained in:
commit
6345e3d5d8
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
## current
|
## current
|
||||||
- Bugfix: Display lifetime stats ib report, not YTD
|
- Bugfix: Display lifetime stats ib report, not YTD
|
||||||
|
- Force expected capitalization on player/goalie names
|
||||||
|
|
||||||
## 0.8.0
|
## 0.8.0
|
||||||
- Bugfix: removed quotation marks from goalie names in report
|
- Bugfix: removed quotation marks from goalie names in report
|
||||||
|
|
|
@ -29,6 +29,7 @@ module Mtlstats.Prompt (
|
||||||
promptController,
|
promptController,
|
||||||
strPrompt,
|
strPrompt,
|
||||||
ucStrPrompt,
|
ucStrPrompt,
|
||||||
|
namePrompt,
|
||||||
numPrompt,
|
numPrompt,
|
||||||
selectPrompt,
|
selectPrompt,
|
||||||
-- * Individual prompts
|
-- * Individual prompts
|
||||||
|
@ -126,6 +127,17 @@ ucStrPrompt
|
||||||
ucStrPrompt pStr act = (strPrompt pStr act)
|
ucStrPrompt pStr act = (strPrompt pStr act)
|
||||||
{ promptProcessChar = \ch -> (++ [toUpper ch]) }
|
{ promptProcessChar = \ch -> (++ [toUpper ch]) }
|
||||||
|
|
||||||
|
-- | Creates a prompt which forces capitalization of input to
|
||||||
|
-- accomodate a player or goalie name
|
||||||
|
namePrompt
|
||||||
|
:: String
|
||||||
|
-- ^ The prompt string
|
||||||
|
-> (String -> Action ())
|
||||||
|
-- ^ The callback function for the result
|
||||||
|
-> Prompt
|
||||||
|
namePrompt pStr act = (strPrompt pStr act)
|
||||||
|
{ promptProcessChar = capitalizeName }
|
||||||
|
|
||||||
-- | Builds a numeric prompt
|
-- | Builds a numeric prompt
|
||||||
numPrompt
|
numPrompt
|
||||||
:: String
|
:: String
|
||||||
|
@ -157,7 +169,7 @@ selectPrompt params = Prompt
|
||||||
in "F" ++ show n ++ ") " ++ desc)
|
in "F" ++ show n ++ ") " ++ desc)
|
||||||
results
|
results
|
||||||
C.moveCursor row col
|
C.moveCursor row col
|
||||||
, promptProcessChar = \ch -> (++[ch])
|
, promptProcessChar = spProcessChar params
|
||||||
, promptAction = \sStr -> if null sStr
|
, promptAction = \sStr -> if null sStr
|
||||||
then spCallback params Nothing
|
then spCallback params Nothing
|
||||||
else do
|
else do
|
||||||
|
@ -186,7 +198,7 @@ playerNumPrompt = numPrompt "Player number: " $
|
||||||
|
|
||||||
-- | Prompts for a new player's name
|
-- | Prompts for a new player's name
|
||||||
playerNamePrompt :: Prompt
|
playerNamePrompt :: Prompt
|
||||||
playerNamePrompt = strPrompt "Player name: " $
|
playerNamePrompt = namePrompt "Player name: " $
|
||||||
modify . (progMode.createPlayerStateL.cpsName .~)
|
modify . (progMode.createPlayerStateL.cpsName .~)
|
||||||
|
|
||||||
-- | Prompts for a new player's position
|
-- | Prompts for a new player's position
|
||||||
|
@ -201,7 +213,7 @@ goalieNumPrompt = numPrompt "Goalie number: " $
|
||||||
|
|
||||||
-- | Prompts for the goalie's name
|
-- | Prompts for the goalie's name
|
||||||
goalieNamePrompt :: Prompt
|
goalieNamePrompt :: Prompt
|
||||||
goalieNamePrompt = strPrompt "Goalie name: " $
|
goalieNamePrompt = namePrompt "Goalie name: " $
|
||||||
modify . (progMode.createGoalieStateL.cgsName .~)
|
modify . (progMode.createGoalieStateL.cgsName .~)
|
||||||
|
|
||||||
-- | Selects a player (creating one if necessary)
|
-- | Selects a player (creating one if necessary)
|
||||||
|
@ -218,6 +230,7 @@ selectPlayerPrompt pStr callback = selectPrompt SelectParams
|
||||||
, spSearch = \sStr db -> playerSearch sStr (db^.dbPlayers)
|
, spSearch = \sStr db -> playerSearch sStr (db^.dbPlayers)
|
||||||
, spSearchExact = \sStr db -> fst <$> playerSearchExact sStr (db^.dbPlayers)
|
, spSearchExact = \sStr db -> fst <$> playerSearchExact sStr (db^.dbPlayers)
|
||||||
, spElemDesc = playerSummary
|
, spElemDesc = playerSummary
|
||||||
|
, spProcessChar = capitalizeName
|
||||||
, spCallback = callback
|
, spCallback = callback
|
||||||
, spNotFound = \sStr -> do
|
, spNotFound = \sStr -> do
|
||||||
mode <- gets (^.progMode)
|
mode <- gets (^.progMode)
|
||||||
|
@ -246,6 +259,7 @@ selectGoaliePrompt pStr callback = selectPrompt SelectParams
|
||||||
, spSearch = \sStr db -> goalieSearch sStr (db^.dbGoalies)
|
, spSearch = \sStr db -> goalieSearch sStr (db^.dbGoalies)
|
||||||
, spSearchExact = \sStr db -> fst <$> goalieSearchExact sStr (db^.dbGoalies)
|
, spSearchExact = \sStr db -> fst <$> goalieSearchExact sStr (db^.dbGoalies)
|
||||||
, spElemDesc = goalieSummary
|
, spElemDesc = goalieSummary
|
||||||
|
, spProcessChar = capitalizeName
|
||||||
, spCallback = callback
|
, spCallback = callback
|
||||||
, spNotFound = \sStr -> do
|
, spNotFound = \sStr -> do
|
||||||
mode <- gets (^.progMode)
|
mode <- gets (^.progMode)
|
||||||
|
|
|
@ -622,6 +622,8 @@ data SelectParams a = SelectParams
|
||||||
-- ^ Search function looking for an exact match
|
-- ^ Search function looking for an exact match
|
||||||
, spElemDesc :: a -> String
|
, spElemDesc :: a -> String
|
||||||
-- ^ Provides a string description of an element
|
-- ^ Provides a string description of an element
|
||||||
|
, spProcessChar :: Char -> String -> String
|
||||||
|
-- ^ Processes a character entered by the user
|
||||||
, spCallback :: Maybe Int -> Action ()
|
, spCallback :: Maybe Int -> Action ()
|
||||||
-- ^ The function when the selection is made
|
-- ^ The function when the selection is made
|
||||||
, spNotFound :: String -> Action ()
|
, spNotFound :: String -> Action ()
|
||||||
|
|
|
@ -19,8 +19,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
module Mtlstats.Util (nth, modifyNth, updateMap, slice) where
|
module Mtlstats.Util
|
||||||
|
( nth
|
||||||
|
, modifyNth
|
||||||
|
, updateMap
|
||||||
|
, slice
|
||||||
|
, capitalizeName
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Data.Char (isSpace, toUpper)
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
|
||||||
-- | Attempt to select the element from a list at a given index
|
-- | Attempt to select the element from a list at a given index
|
||||||
|
@ -75,3 +82,25 @@ slice
|
||||||
-- ^ The list to take a subset of
|
-- ^ The list to take a subset of
|
||||||
-> [a]
|
-> [a]
|
||||||
slice offset len = take len . drop offset
|
slice offset len = take len . drop offset
|
||||||
|
|
||||||
|
-- | Name capitalization function for a player
|
||||||
|
capitalizeName
|
||||||
|
:: Char
|
||||||
|
-- ^ The character being input
|
||||||
|
-> String
|
||||||
|
-- ^ The current string
|
||||||
|
-> String
|
||||||
|
-- ^ The resulting string
|
||||||
|
capitalizeName ch str = str ++ [ch']
|
||||||
|
where
|
||||||
|
ch' = if lockFlag str
|
||||||
|
then toUpper ch
|
||||||
|
else ch
|
||||||
|
lockFlag "" = True
|
||||||
|
lockFlag (c:cs)
|
||||||
|
| c == ',' = lockFlag' cs
|
||||||
|
| otherwise = lockFlag cs
|
||||||
|
lockFlag' "" = True
|
||||||
|
lockFlag' (c:cs)
|
||||||
|
| isSpace c = lockFlag' cs
|
||||||
|
| otherwise = False
|
||||||
|
|
|
@ -32,6 +32,7 @@ spec = describe "Mtlstats.Util" $ do
|
||||||
modifyNthSpec
|
modifyNthSpec
|
||||||
updateMapSpec
|
updateMapSpec
|
||||||
sliceSpec
|
sliceSpec
|
||||||
|
capitalizeNameSpec
|
||||||
|
|
||||||
nthSpec :: Spec
|
nthSpec :: Spec
|
||||||
nthSpec = describe "nth" $ mapM_
|
nthSpec = describe "nth" $ mapM_
|
||||||
|
@ -93,3 +94,23 @@ sliceSpec = describe "slice" $ do
|
||||||
context "negative offset" $
|
context "negative offset" $
|
||||||
it "should return the correct number of elements from the beginning" $
|
it "should return the correct number of elements from the beginning" $
|
||||||
slice (-10) 2 list `shouldBe` [2, 4]
|
slice (-10) 2 list `shouldBe` [2, 4]
|
||||||
|
|
||||||
|
capitalizeNameSpec :: Spec
|
||||||
|
capitalizeNameSpec = describe "capitalizeName" $ mapM_
|
||||||
|
(\(label, ch, str, expected) -> context label $
|
||||||
|
it ("should be " ++ expected) $
|
||||||
|
capitalizeName ch str `shouldBe` expected)
|
||||||
|
-- label, character, string, expected
|
||||||
|
[ ( "initial lower", 'a', "", "A" )
|
||||||
|
, ( "initial upper", 'A', "", "A" )
|
||||||
|
, ( "initial non-alpha", '0', "", "0" )
|
||||||
|
, ( "pre-comma lower", 'a', "A", "AA" )
|
||||||
|
, ( "pre-comma upper", 'A', "A", "AA" )
|
||||||
|
, ( "pre-comma non-alpha", '0', "A", "A0" )
|
||||||
|
, ( "post-comma first lower", 'a', "FOO, ", "FOO, A" )
|
||||||
|
, ( "post-comma first upper", 'A', "FOO, ", "FOO, A" )
|
||||||
|
, ( "post-comma first non-alpha", '0', "FOO, ", "FOO, 0" )
|
||||||
|
, ( "unrestricted upper", 'A', "FOO, A", "FOO, AA" )
|
||||||
|
, ( "unrestricted lower", 'a', "FOO, A", "FOO, Aa" )
|
||||||
|
, ( "unrestricted non-alpha", '0', "FOO, A", "FOO, A0" )
|
||||||
|
]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user