Skip to content

Commit

Permalink
Set termType directly on class.
Browse files Browse the repository at this point in the history
Fixes #172
  • Loading branch information
RubenVerborgh committed Apr 22, 2019
1 parent e9e35da commit c78adda
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions lib/N3DataFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ class Term {
this.id = id;
}

// ### The term type of this term
get termType() {
return this.constructor.name;
}

// ### The value of this term
get value() {
return this.id;
Expand Down Expand Up @@ -46,12 +41,20 @@ class Term {


// ## NamedNode constructor
class NamedNode extends Term {}
NamedNode.name = 'NamedNode';

class NamedNode extends Term {
// ### The term type of this term
get termType() {
return 'NamedNode';
}
}

// ## Literal constructor
class Literal extends Term {
// ### The term type of this term
get termType() {
return 'Literal';
}

// ### The text value of this literal
get value() {
return this.id.substring(1, this.id.lastIndexOf('"'));
Expand Down Expand Up @@ -103,32 +106,39 @@ class Literal extends Term {
};
}
}
Literal.name = 'Literal';

// ## BlankNode constructor
class BlankNode extends Term {
constructor(name) {
super('_:' + name);
}

// ### The term type of this term
get termType() {
return 'BlankNode';
}

// ### The name of this blank node
get value() {
return this.id.substr(2);
}
}
BlankNode.name = 'BlankNode';

class Variable extends Term {
constructor(name) {
super('?' + name);
}

// ### The term type of this term
get termType() {
return 'Variable';
}

// ### The name of this variable
get value() {
return this.id.substr(1);
}
}
Variable.name = 'Variable';

// ## DefaultGraph constructor
class DefaultGraph extends Term {
Expand All @@ -137,6 +147,11 @@ class DefaultGraph extends Term {
return DEFAULTGRAPH || this;
}

// ### The term type of this term
get termType() {
return 'DefaultGraph';
}

// ### Returns whether this object represents the same term as the other
equals(other) {
// If both terms were created by this library,
Expand All @@ -145,7 +160,6 @@ class DefaultGraph extends Term {
return (this === other) || (!!other && (this.termType === other.termType));
}
}
DefaultGraph.name = 'DefaultGraph';

// ## DefaultGraph singleton
DEFAULTGRAPH = new DefaultGraph();
Expand Down

0 comments on commit c78adda

Please sign in to comment.