Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 40 lines (34 sloc) 1.012 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
use v6;

class ABC::Header {
    has @.lines; # array of Pairs representing each line of the ABC header
    
    method add-line($name, $data) {
        self.lines.push($name => $data);
    }

    method set-key($new-key) {
        my $found = False;
        for self.lines <-> $line {
            if $line.key eq "K" {
                $line.value = $new-key;
                $found = True;
            }
        }
        self.lines.push("K" => $new-key) unless $found;
    }
    
    method get($name) {
        self.lines.grep({ .key eq $name });
    }

    method get-first-value($name) {
        my $pair = self.lines.first({ .key eq $name });
        $pair ?? $pair.value !! Any;
    }
    
    method is-valid() {
        self.lines.elems > 1
        && self.lines[0].key eq "X"
        && self.get("T").elems > 0
        && self.get("M").elems == 1
        && self.get("L").elems == 1
        && self.get("X").elems == 1
        && self.get("K").elems == 1
        && self.lines[*-1].key eq "K";
    }
}
Something went wrong with that request. Please try again.