-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUsMailV2RecipientAddress.php
More file actions
124 lines (116 loc) · 4.48 KB
/
Copy pathUsMailV2RecipientAddress.php
File metadata and controls
124 lines (116 loc) · 4.48 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
namespace Mindee\Product\Us\UsMail;
use Mindee\Parsing\Common\SummaryHelper;
use Mindee\Parsing\Standard\FieldConfidenceMixin;
use Mindee\Parsing\Standard\FieldPositionMixin;
/**
* The addresses of the recipients.
*/
class UsMailV2RecipientAddress
{
use FieldPositionMixin;
use FieldConfidenceMixin;
/**
* @var string|null The city of the recipient's address.
*/
public ?string $city;
/**
* @var string|null The complete address of the recipient.
*/
public ?string $complete;
/**
* @var boolean Indicates if the recipient's address is a change of address.
*/
public bool $isAddressChange;
/**
* @var string|null The postal code of the recipient's address.
*/
public ?string $postalCode;
/**
* @var string|null The private mailbox number of the recipient's address.
*/
public ?string $privateMailboxNumber;
/**
* @var string|null Second part of the ISO 3166-2 code, consisting of two letters indicating the US State.
*/
public ?string $state;
/**
* @var string|null The street of the recipient's address.
*/
public ?string $street;
/**
* @param array $rawPrediction Array containing the JSON document response.
* @param integer|null $pageId Page number for multi pages document.
*/
public function __construct(array $rawPrediction, ?int $pageId)
{
$this->setConfidence($rawPrediction);
$this->setPosition($rawPrediction);
$this->city = $rawPrediction["city"] ?? null;
$this->complete = $rawPrediction["complete"] ?? null;
$this->isAddressChange = $rawPrediction["is_address_change"] ?? null;
$this->postalCode = $rawPrediction["postal_code"] ?? null;
$this->privateMailboxNumber = $rawPrediction["private_mailbox_number"] ?? null;
$this->state = $rawPrediction["state"] ?? null;
$this->street = $rawPrediction["street"] ?? null;
}
/**
* Return values for printing inside an RST table.
*
* @return array
*/
private function tablePrintableValues(): array
{
$outArr = [];
$outArr["city"] = SummaryHelper::formatForDisplay($this->city, 15);
$outArr["complete"] = SummaryHelper::formatForDisplay($this->complete, 35);
$outArr["isAddressChange"] = SummaryHelper::formatForDisplay($this->isAddressChange);
$outArr["postalCode"] = SummaryHelper::formatForDisplay($this->postalCode);
$outArr["privateMailboxNumber"] = SummaryHelper::formatForDisplay($this->privateMailboxNumber);
$outArr["state"] = SummaryHelper::formatForDisplay($this->state);
$outArr["street"] = SummaryHelper::formatForDisplay($this->street, 25);
return $outArr;
}
/**
* Return values for printing as an array.
*
* @return array
*/
private function printableValues(): array
{
$outArr = [];
$outArr["city"] = SummaryHelper::formatForDisplay($this->city);
$outArr["complete"] = SummaryHelper::formatForDisplay($this->complete);
$outArr["isAddressChange"] = SummaryHelper::formatForDisplay($this->isAddressChange);
$outArr["postalCode"] = SummaryHelper::formatForDisplay($this->postalCode);
$outArr["privateMailboxNumber"] = SummaryHelper::formatForDisplay($this->privateMailboxNumber);
$outArr["state"] = SummaryHelper::formatForDisplay($this->state);
$outArr["street"] = SummaryHelper::formatForDisplay($this->street);
return $outArr;
}
/**
* Output in a format suitable for inclusion in an rST table.
*
* @return string
*/
public function toTableLine(): string
{
$printable = $this->tablePrintableValues();
$outStr = "| ";
$outStr .= SummaryHelper::padString($printable["city"], 15);
$outStr .= SummaryHelper::padString($printable["complete"], 35);
$outStr .= SummaryHelper::padString($printable["isAddressChange"], 17);
$outStr .= SummaryHelper::padString($printable["postalCode"], 11);
$outStr .= SummaryHelper::padString($printable["privateMailboxNumber"], 22);
$outStr .= SummaryHelper::padString($printable["state"], 5);
$outStr .= SummaryHelper::padString($printable["street"], 25);
return rtrim(SummaryHelper::cleanOutString($outStr));
}
/**
* @return string String representation.
*/
public function __toString(): string
{
return SummaryHelper::cleanOutString($this->toTableLine());
}
}