Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 40 lines (34 sloc) 1.012 kb
f1ff993 Solomon Foster Start to add ABC::Header.
authored
1 use v6;
2
3 class ABC::Header {
4 has @.lines; # array of Pairs representing each line of the ABC header
5
2787937 Solomon Foster Switch "our method" to just plain "method".
authored
6 method add-line($name, $data) {
f1ff993 Solomon Foster Start to add ABC::Header.
authored
7 self.lines.push($name => $data);
8 }
512cc71 Solomon Foster Get basic (if slightly stupid) transpose working.
authored
9
10 method set-key($new-key) {
11 my $found = False;
12 for self.lines <-> $line {
13 if $line.key eq "K" {
14 $line.value = $new-key;
15 $found = True;
16 }
17 }
18 self.lines.push("K" => $new-key) unless $found;
19 }
f1ff993 Solomon Foster Start to add ABC::Header.
authored
20
2787937 Solomon Foster Switch "our method" to just plain "method".
authored
21 method get($name) {
f1ff993 Solomon Foster Start to add ABC::Header.
authored
22 self.lines.grep({ .key eq $name });
23 }
d6fa923 Solomon Foster Clean up.
authored
24
2787937 Solomon Foster Switch "our method" to just plain "method".
authored
25 method get-first-value($name) {
d6fa923 Solomon Foster Clean up.
authored
26 my $pair = self.lines.first({ .key eq $name });
27 $pair ?? $pair.value !! Any;
28 }
ee2c5f6 Solomon Foster Add ABC::Header.is-valid and ABC::Actions.
authored
29
2787937 Solomon Foster Switch "our method" to just plain "method".
authored
30 method is-valid() {
ee2c5f6 Solomon Foster Add ABC::Header.is-valid and ABC::Actions.
authored
31 self.lines.elems > 1
32 && self.lines[0].key eq "X"
33 && self.get("T").elems > 0
34 && self.get("M").elems == 1
35 && self.get("L").elems == 1
36 && self.get("X").elems == 1
37 && self.get("K").elems == 1
38 && self.lines[*-1].key eq "K";
39 }
f1ff993 Solomon Foster Start to add ABC::Header.
authored
40 }
Something went wrong with that request. Please try again.