Skip to content
Browse files

Normalize names in output

  • Loading branch information...
1 parent 5939dd7 commit 535cfc9b99fe596e8962fde4dade92eea0d5de4c @kevinsawicki committed May 18, 2013
Showing with 19 additions and 2 deletions.
  1. +6 −0 spec/names-spec.coffee
  2. +1 −0 src/filings.coffee
  3. +2 −2 src/flips-cli.coffee
  4. +10 −0 src/names.coffee
View
6 spec/names-spec.coffee
@@ -0,0 +1,6 @@
+names = require '../lib/names'
+
+describe 'names', ->
+ describe '.normalize()', ->
+ it 'normalizes names', ->
+ expect(names.normalize('HURD MARK V')).toBe 'Mark V. Hurd'
View
1 src/filings.coffee
@@ -4,3 +4,4 @@ module.exports =
Connection: require('./connection')
Transactions: require('./transactions')
Companies: require('./companies')
+ Names: require ('./names')
View
4 src/flips-cli.coffee
@@ -3,7 +3,7 @@ path = require 'path'
optimist = require 'optimist'
async = require 'async'
humanize = require 'humanize-plus'
-{Connection, Transactions, FormFour} = require './filings'
+{Names, Connection, Transactions, FormFour} = require './filings'
parseOptions = (args=[]) ->
options = optimist(args)
@@ -27,7 +27,7 @@ fetchTransaction = ({connection, transaction}, callback) ->
day = "0#{day}" if date.length is 1
date = "#{month}/#{day}/#{date.getFullYear()}"
owner = form.getOwner()
- console.log date, "$#{humanize.intcomma(Math.floor(profit))} #{owner.name} #{owner.title}"
+ console.log date, "$#{humanize.intcomma(Math.floor(profit))} #{Names.normalize(owner.name)} #{owner.title}"
callback()
module.exports =
View
10 src/names.coffee
@@ -0,0 +1,10 @@
+humanize = require 'humanize-plus'
+
+module.exports =
+ normalize: (name='') ->
+ name = name.toLowerCase()
+ segments = name.split(' ')
+ segments.push(segments.shift())
+ for segment, index in segments
+ segments[index] = "#{segment}." if segment.length is 1
+ humanize.titlecase(segments.join(' '))

0 comments on commit 535cfc9

Please sign in to comment.
Something went wrong with that request. Please try again.