-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re-factoring to add more sentence types
- Loading branch information
James Thomas
committed
May 30, 2017
1 parent
f52d75b
commit c03e58b
Showing
8 changed files
with
201 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
'use strict' | ||
|
||
const Sentence = require('./src/sentence') | ||
const Sentences = require('./src/sentences') | ||
|
||
module.exports = { | ||
Sentence | ||
Sentences | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict' | ||
|
||
class Concept { | ||
constructor (property, value) { | ||
this.concept = { property, value } | ||
this.clauses = [] | ||
} | ||
|
||
is (parentConcept) { | ||
this.clauses.push(`is a ${parentConcept}`) | ||
return this | ||
} | ||
|
||
value (letter, property) { | ||
this.clauses.push(`has the value ${letter} as ~ ${property} ~`) | ||
return this | ||
} | ||
|
||
property (relationship, name, letter) { | ||
this.clauses.push(`~ ${relationship} ~ the ${name} ${letter}`) | ||
return this | ||
} | ||
|
||
toString () { | ||
let conceptString = `conceptualise a ~ ${this.concept.property} ~ ${this.concept.value}` | ||
|
||
if (this.clauses.length) { | ||
const clausesString = this.clauses.join(' and ') | ||
|
||
conceptString = `${conceptString} that ${clausesString}` | ||
} | ||
|
||
return `${conceptString}.` | ||
} | ||
} | ||
|
||
module.exports = Concept |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict' | ||
|
||
const Instance = require('./instance') | ||
|
||
class ExtendInstance extends Instance { | ||
prefix () { | ||
return `the ${this.instance.concept} ${this.instance.name}` | ||
} | ||
} | ||
|
||
module.exports = ExtendInstance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict' | ||
|
||
class Instance { | ||
constructor (concept, name) { | ||
this.instance = { concept, name} | ||
this.clauses = [] | ||
} | ||
|
||
is (name, concept, value) { | ||
this.clauses.push(`is the ${name} of the ${concept} ${value}`) | ||
return this | ||
} | ||
|
||
has (property, concept) { | ||
this.clauses.push(`has \'${property}\' as ${concept}`) | ||
return this | ||
} | ||
|
||
has_clauses () { | ||
return !!this.clauses.length | ||
} | ||
|
||
prefix () { | ||
let prefix = `there is a ${this.instance.concept} named ${this.instance.name}` | ||
return this.has_clauses() ? `${prefix} that` : prefix | ||
} | ||
|
||
toString () { | ||
let conceptString = this.prefix() | ||
|
||
if (this.has_clauses()) { | ||
const clausesString = this.clauses.join(' and ') | ||
|
||
conceptString = `${conceptString} ${clausesString}` | ||
} | ||
|
||
return `${conceptString}.` | ||
} | ||
} | ||
|
||
module.exports = Instance |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict' | ||
|
||
const sentencesSymbol = Symbol('sentences') | ||
|
||
const Concept = require('./concept') | ||
const Instance = require('./instance') | ||
const ExtendInstance = require('./extend_instance') | ||
|
||
class Sentences { | ||
constructor () { | ||
this[sentencesSymbol] = [] | ||
} | ||
|
||
toString () { | ||
return this[sentencesSymbol] | ||
.map(sentence => sentence.toString()) | ||
.join(' ') | ||
} | ||
|
||
concept (property, value) { | ||
return this.sentence(new Concept(property, value)) | ||
} | ||
|
||
there_is_a (concept, instance) { | ||
return this.sentence(new Instance(concept, instance)) | ||
} | ||
|
||
the (concept, instance) { | ||
return this.sentence(new ExtendInstance(concept, instance)) | ||
} | ||
|
||
sentence (klass) { | ||
this[sentencesSymbol].push(klass) | ||
return klass | ||
} | ||
} | ||
|
||
module.exports = Sentences |
Oops, something went wrong.