Giter VIP home page Giter VIP logo

gp-assignment's Introduction

Python Address book

This is a simple address book python implementation.

Test

  1. Install dependencies pip install -r requirements_dev.txt.
  2. Run nosetests or run nosetests --with-coverag to run test with coverage report.

Test Coverage

Package is 100% test Coverage

Name Stmts Miss Cover
address_book/__init__.py 0 0 100%
address_book/base.py 6 0 100%
address_book/models.py 46 0 100%
TOTAL 163 0 100%

Usage

Create Person and add person to Address Book.

from address_book import models

address_book = models.AddressBook()

person = models.Person('Jack', 'Scoot')
person.add_email = '[email protected]'
person.add_address = 'Alex Company, Random Street'
person.add_phone_number = '999-999-9999'

address_book.add_person(person)

Create person and add person to teh address book and group

from address_book import models

address_book = models.AddressBook()

person = models.Person('Jack', 'Scoot')
person.add_email = '[email protected]'
person.add_address = 'Alex Company, Random Street'
person.add_phone_number = '999-999-9999'

group = models.Group('Friends')
group.add_member(person)

address_book.add_person(person)
address_book.add_group(group)

Create group and add group to the address book

from address_book import models

address_book = models.AddressBook()

group = models.Group('Friends')

address_book.add_group(group)

Find person in address book by name

from address_book import models

address_book = models.AddressBook()

person = address_book.find_person_by_name('Jack')

print(person.get_full_name())
>>> Jack Scott

Find person in address book by email

from address_book import models

address_book = models.AddressBook()

person = address_book.find_person_by_email('[email protected]')

print(person.get_full_name())
>>> Jack Scott

Address book APIs

class AddressBook()

Phone address book is a collection of persons and groups. It's implemented as Singleton, so you will have one instance of address book in package

Attributes

groups type: set()
persons type: set()

Methods

add_person(person)

Add person to address book

parameters
  • person: person object
add_group(group)

Add group to address book

parameters
  • group: group object
find_person_by_email(email)

Find person by email address (can supply either the exact string or a prefix string) ie. both "[email protected]" and "alex" should work. group

parameters
  • email: person's email an supply either the exact string or a prefix string
return
  • First person found
find_person_by_name(search_term)

Find person by name (can supply either first name, last name, or both)

parameters
  • search_term: either person's first name, last name, or both
return
  • First person found

--

class Person()

Person contact information

  • A person has a first name and a last name.
  • A person has one or more street addresses.
  • A person has one or more email addresses.
  • A person has one or more phone numbers.
  • A person can be a member of one or more groups.

Attributes

first_name as string
last_name as string
addresses as set()
emails as set()
phone_numbers as set()
in_groups as set()

Methods

add_address(address)

Add address to person information

parameters
  • address: person's address to be added
add_email(email)

Add email to person information

parameters
  • email: person's email to be added

add_phone_number(phone_number)

Add phone number to person information

parameters
  • phone_number: person's phone number to be added
get_full_name()

Return person's full name

return
  • person's full name

--

class Group()

Persons Group

Attributes

name type string
members type set()

Methods

add_member(person)

Add member to the group

parameters
  • person: person who will be a member in group

--

Design Question

Find person by email address (can supply any substring, ie. "comp" should work assuming "[email protected]" is an email address in the address book)

If we aggregate the persons's contact information regardless of the type of information like this:

{'contact_info': ['[email protected]'
                   'Alex Company, Random Street',
                   ...
                  ]
}

We can search for comp in the contact_info, or more better is creating a method that aggregate the contact information and return it as on string and search for comp in it, but these soltion will have big time complexity for that we can gather all of these information in text file or json file and update the file everytime user add a conntact informtaiont to the person object.

gp-assignment's People

Contributors

emadmokhtar avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.