aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Edition/Edition.elm
blob: be7aa02e562f4e5c086d2ab97df2776eb578a9f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module Model.Edition.Edition
  ( Edition
  , Kind(..)
  , newEdition
  , keyCodeToChar
  , isEmpty
  ) where

import Keyboard (KeyCode)
import String

import Model.Id (..)
import Model.Edition.NameEdition as NameEdition
import Model.Edition.TimeEdition as TimeEdition

type alias Edition =
  { id : Id
  , kind : Kind
  , chars : List Char
  }

type Kind =
  Name
  | Time

newEdition id kind =
  { id = id
  , kind = kind
  , chars = []
  }

keyCodeToChar : Kind -> KeyCode -> Maybe Char
keyCodeToChar kind =
  case kind of
    Name -> NameEdition.keyCodeToChar
    Time -> TimeEdition.keyCodeToChar

isEmpty : Edition -> Bool
isEmpty edition =
  edition.chars
    |> String.fromList
    |> String.trim
    |> String.length
    |> (==) 0