models/horse.js

import { article, sentenceCase, toLink } from "../string_utils.js";
import Model from "./model.js";

/**
 * A horse. Because most people (myself included) don’t know horse appearance and how it’s
 * described, we’re experimenting here with linking out to an image search.
 */
export default class Horse extends Model {
  constructor({ name, behavior, pattern, bag, gender, type, effect, guid } = {}) {
    super({ tags: [], guid });
    this.name = name;
    this.behavior = behavior;
    this.pattern = pattern;
    this.gender = gender;
    this.type = type;
    this.effect = effect;
    this.bag = bag;
    this._class = "Horse";
  }
  toLink() {
    // TODO: This needs to be centralized
    return `https://duckduckgo.com/?t=ffab&q=${this.pattern}+${this.type}&ia=images&iax=images`;
  }
  #to(insertString, includeName = true) {
    let arr = [];
    arr.push(this.behavior);
    if (includeName) {
      arr.push(insertString);
      arr.push("named");
      arr.push(`${this.name}.`);
    } else {
      arr.push(`${insertString}.`);
    }
    if (this.effect) {
      arr.push(`${this.effect}.`);
    }
    return article(arr.join(" "));
  }
  #str() {
    return `${this.pattern} ${this.type}`;
  }
  toHtml() {
    return this.#to(`<a target="_blank" href="${toLink(this.#str())}">${this.#str()}</a>`);
  }
  toHtmlWithoutName() {
    return this.#to(`<a target="_blank" href="${toLink(this.#str())}">${this.#str()}</a>`, false);
  }
  toString() {
    return this.#to(this.#str());
  }
  toTitleString() {
    return this.name;
  }
  getDisplayProps() {
    return { _gender: this.gender };
  }
  toDetailHtml() {
    return this.toHtmlWithoutName();
  }
}