Guest User

Untitled

a guest
Aug 30th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Word
  2.     constructor: (@word) ->
  3.  
  4.     getWord: ->
  5.         @word.trim()
  6.  
  7. class WordGroup
  8.     constructor: ->
  9.         @end = []
  10.  
  11.     print: (cb) ->
  12.         words = @process @end
  13.  
  14.         if typeof cb is 'function'
  15.             cb words
  16.         else
  17.             console.log(words)
  18.  
  19.         return this
  20.  
  21. class Sentence extends WordGroup
  22.     addWord: (word) ->
  23.         word = new Word word if typeof word is 'string'
  24.         word = word.getWord?()
  25.         @end.push word if word
  26.         return this
  27.  
  28.     process: ->
  29.         words = @end.join ' '
  30.         words[0].toUpperCase() + words.slice(1) + '.'
  31.  
  32. class Paragraph extends WordGroup
  33.     addSentence: (sentence) ->
  34.         sentence.print (string) =>
  35.             @end.push string if string
  36.        
  37.         return this
  38.  
  39.     process: ->
  40.         @end.join '  '
Add Comment
Please, Sign In to add comment