Skip to content

Commit

Permalink
feat(#49): lines, hash-split
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed Mar 19, 2024
1 parent 5340624 commit 35199b4
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/blob-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export class BlobPath implements Scalar<string | undefined> {
const match = this.body?.match(pattern);
let path;
if (match) {
const full = match[1];
path = full.split("#")[0];
path = match[1];
// path = full.split("#")[0];
} else {
throw new Error(
`Asset body ${this.body} does not contain puzzle blob, regex: ${pattern}`
Expand Down
40 changes: 40 additions & 0 deletions src/hash-split.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023-2024 Tracehub.git
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/**
* Split it by hash.
*/
export class HashSplit implements Scalar<string | undefined> {

/**
* Ctor.
* @param full Full path
*/
constructor(private readonly full: string | undefined) {
}

value(): string | undefined {
return this.full?.split("#")[0];
}
}
40 changes: 40 additions & 0 deletions src/lines.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023-2024 Tracehub.git
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/**
* Lines.
*/
export class Lines implements Scalar<string> {

/**
* Ctor.
* @param body Report body
*/
constructor(private readonly body: string | undefined) {
}

value(): string {
return "1-5";
}
}
7 changes: 5 additions & 2 deletions src/pdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {Ranged} from "./ranged";
import {Blob} from "./blob";
import {Octokit} from "@octokit/rest";
import {BlobPath} from "./blob-path";
import {Lines} from "./lines";
import {HashSplit} from "./hash-split";

/**
* PDD routine.
Expand All @@ -48,9 +50,10 @@ export class Pdd {
* Run it.
*/
async run() {
const path = new BlobPath(this.body).value();
const puzzle = await new Ranged(
new Blob(this.github, this.issue, new BlobPath(this.body)),
"1-5"
new Blob(this.github, this.issue, new HashSplit(path)),
new Lines(path)
).value();
console.log(puzzle);
}
Expand Down
11 changes: 6 additions & 5 deletions src/ranged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ export class Ranged implements Scalar<Promise<any>> {
*/
async value() {
const content = await this.origin.value();
const value = this.range.value();
let result;
if (this.range.includes('-')) {
const start = this.range.split("-")[0] - 1;
const end = this.range.split("-")[1];
if (value.includes('-')) {
const start = value.split("-")[0] - 1;
const end = value.split("-")[1];
result = content.splice(start, end).join("\r\n");
} else if (parseInt(this.range)) {
result = content[parseInt(this.range) - 1];
} else if (parseInt(value)) {
result = content[parseInt(value) - 1];
}
return result;
}
Expand Down

0 comments on commit 35199b4

Please sign in to comment.