-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPSChristmas.psm1
77 lines (62 loc) · 1.86 KB
/
PSChristmas.psm1
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<#
A demo PowerShell class-based module
#>
#dot source helper functions
Get-ChildItem -Path $PSScriptRoot\functions\*.ps1 | ForEach-Object {
. $_.FullName
}
#region Class
Enum ListStatus {
Naughty
Nice
}
Class PSChristmas {
#class properties
[string]$Greeting
[string]$ElfName
[ListStatus]$List
[string]$ChristmasDay
[int32]$DaysRemaining
[string]$CountDown
#class methods
[void]Refresh() {
Write-Verbose '[CLASS] Invoking Refresh()'
#calculate christmas for the current year that should be culture aware
$Christmas = [datetime]::new( (Get-Date).Year, 12, 25)
Write-Verbose "[CLASS] Christmas this year is $Christmas"
$this.ChristmasDay = $Christmas.DayOfWeek
$span = $Christmas - (Get-Date)
$this.DaysRemaining = $span.totalDays
#strip off milliseconds
$TimeString = $span.ToString()
$this.CountDown = $TimeString.Substring(0, $TimeString.LastIndexOf('.'))
Write-Verbose '[CLASS] Getting new greeting'
$this.Greeting = New-PSChristmasGreeting
}
[void]Play() {
Write-Verbose '[CLASS] Invoking Play()'
PlayTune
}
[void]Show() {
Write-Verbose '[CLASS] Invoking Show()'
ShowGraphic
}
#class constructor
PSChristmas() {
Write-Verbose '[CLASS] Invoking Constructor'
$this.ElfName = New-ElfName
if ( (Get-Date).Second % 2) {
$this.List = [ListStatus]::Naughty
}
else {
$this.List = [ListStatus]::Nice
}
#set the rest of the properties by invoking the defined
#Refresh() method
$this.Refresh()
}
} #close class definition
#endregion
#import data from json
$xmasData = Get-Content $PSScriptRoot\data.json | ConvertFrom-Json
Export-ModuleMember -Variable xmasData -Alias 'elfme', 'jingle', 'wf'