Code Document - Assembla

granddetourfannieInternet and Web Development

Feb 2, 2013 (4 years and 9 months ago)

139 views



Code

Document

WinVictory


This document presents a quick overview of the code that will be reviewed on
code review week for Ron Mak’s Software Engineering course.

周T⁣on瑥n瑳f
瑨t猠摯捵m敮e⁩湣 uT攺

ove牶楥if⁴h攠prog牡mm楮g⁦牡 e睯r欬kt散桮楣慬
獰散楦s捡瑩on猠o映fh攠獹獴smⰠ慮,⁰ oTu捴con⁣oT攮


2008

Christopher Archibald, Andrei Bog
atsky, Brian Cobarrubia, Andrew
Macheret, Kevin Simonich, Don Trinh, Cheuk Wong

WinVictory



M慲aMyP慰e爮捯m

4/8/2
008

Code Document

2008


2

WinVictory
-

Confidential


Introduction

The purpose of this document is to highlight a section of our code that will be presented for the code
review on the week of April 14


April 18. The code review will contain sections of our project that deal
specifically with uploading a
nd retrieving documents that we have worked on over the past two months.
To understand the code that will be presented, there will be a quick overview covering
on these topics
:



RUBY REVIEW

o

The Ruby Programming Language

o

The Ruby On Rails Web Application Fr
amework



TECHNICAL REVIEW

o

The Flowchart of our Web Architecture



CODE OVERVIEW

o

The Website GUI Layout

o

The Backend Code

Ruby Review

Ruby Programming Language

T
he Ruby programming language implements multiple programming paradigms such as object oriented,
func
tional, and imperative
. S
yntactically
, Ruby resembles

Python, Perl, and Lisp

in that it emphasizes
simplicity and readability
.

Data types in Ruby are all treated as objects

unlike in Java, which uses
primi
tives, function calls are possible on these data
types:
integers, booleans, and chars.

This is

an example comparing how Java and Ruby implement
s

a
behavioral method

that sets the last
name for a Person object
.

An Example of
Java

Code:










public void marry(Person other) {


String newLastName =


String.format(“%s
-
%s”,getLastName(), other.getLastName());


setLastName(newLastName);


other.setLastName(newLastName);

}

Code Document

2008


3

WinVictory
-

Confidential



An Example

of Ruby

Code:






From this example we can see
that Ruby always returns the last expression evaluated, so multiple
setters can be chained toget
her. Also notice that
the word
self

in Ruby is equivalent to how objects in
Java refers to itself using the
this

word.

For more information on the Ruby program
ming language refer to the Sources section.

Ruby On Rails Web Application Framework

Ruby is slowly gaining momentum as a viable programming language for quick
prototyping and web development.
Following current trends,
agile
development methodologies fit
well
with the Ruby on Rails philosophy.

It is
very flexible
as it is build on the

Model
-
View
-
Controller

architecture and
provides all the necessary tool to start developing web applications.

Our decision to go with Ruby On Rails instead of other framework
s such as
CakePHP, Apache Struts, Catalyst, etc. was because of the Ruby programming
language, quick prototyping, and ease of setup.
We used a portable Rails
runtime solution which contains all of the necessary tools pre
-
configured and ready to go. The t
ools
include the latest version of the Ruby programming language, Rails framework, Apache Web Server, and
MySQL.


def marry(other)

other.last_name = self.last_name = “#{self.last_name
}

-

#{other.last_name}”

end

Code Document

2008


4

WinVictory
-

Confidential



Technical Review

The Layout of Our System

Our system’s website is called MarkMyPaper and it is located at
http://www.markmypaper.com
. As of
now it is a placeholder of how our website will look and will soon run on Rails.

The main home page of
the site

will lead to several links that will

allow

the user to submit their paper. From there a
confirmation
will show up to indicate the status of the submission while in the backend the document
will be parsed, compared with other documents, and an email to confirm the status of plagiarism will be
sent to the user. When the user gets the email they get a link
to a results page detailing how much of
their document was plagiarized and from where.

The Flowchart of our current system



Code Document

2008


5

WinVictory
-

Confidential



Code Overview

Website GUI Layout

The layout of our web pages will consist
of html pages and some AJAX will be implemented. The p
ages
will call and send information to the backend which the parser programmed in Ruby will then handle, it
will be autonomous then.

This is the current iteration of our website, we’ve simplified a lot of the functionality of the website
because most of th
e flash stuff

took too long to load up

and we needed to get the main function of the
website to work.

It will mos
t likely change again in the next iteration

a
s we cut down or architect a more
efficient solution.



Code Document

2008


6

WinVictory
-

Confidential



The Backend Code

This is a small sampl
e of the
Ruby
code
used to establish the database that will contain each of the
papers that have been submitted
,

it will store the papers for later use in the phrase database.










This is another sample of the Ruby code that
will establish the datab
ase that

will contain the phrases.
The phrases will be an importan
t part of the system as this is what is being compared against in the
document.











class CreatePapers < ActiveRecord::Migration


def self.up


create_table :papers do |t|


t.string :title


t.string :uid


t.text :paper



t.timestamps


end


end



def self.down


drop_table :papers


end

end


def self.down


drop_table :phrases


end

end

class CreatePhrases < ActiveRecord::Migration


def self.up


create_table :phrases do |t|


t.string :phraseNum


t.string :paperId


t.text :phrase



t.references :paper


t.timestamps


end


end



def self.down


drop_table :phrases


end

end


def self.down


drop_table :papers


end

end


def self.down


drop_table :phrases


end

end

Code Document

2008


7

WinVictory
-

Confidential


Our final sample of code is one of the more important parts, it is the papers_
controller.rb
code wh
ich
manages the controller part of our MVC architecture.




















class PapersController < ApplicationController


# GET /papers


# GET /papers
.xml


def index


@papers = Paper.find(:all)



respond_to do |format|


format.html # index.html.erb


format.xml { render :xml => @papers }


end


end



# GET /papers/1


# GET /papers/1.xml


def show


@paper = Paper.find(params[:id
])



respond_to do |format|


format.html # show.html.erb


format.xml { render :xml => @paper }


end


end



# GET /papers/new


# GET /papers/new.xml


def new


@paper = Paper.new



respond_to do |format|


format.html # new.htm
l.erb


format.xml { render :xml => @paper }


end


end



# GET /papers/1/edit


def edit


@paper = Paper.find(params[:id])


end


Code Document

2008


8

WinVictory
-

Confidential


The code continues onto the next page where the backend handles formatting and uploading the text
into the database.


























# POST /papers


# POST /papers.xml


def create


@paper = Paper.new(params[:paper])



respond_to do |fo
rmat|


if @paper.save


flash[:notice] = 'Paper was successfully created.'


format.html { redirect_to(@paper) }


format.xml { render :xml => @paper, :status => :created, :location
=> @paper }


else


format.html { rende
r :action => "new" }


format.xml { render :xml => @paper.errors, :status =>
:unprocessable_entity }


end


end


end



# PUT /papers/1


# PUT /papers/1.xml


def update


@paper = Paper.find(params[:id])



respond_to do |format|



if @paper.update_attributes(params[:paper])


flash[:notice] = 'Paper was successfully updated.'


format.html { redirect_to(@paper) }


format.xml { head :ok }


else


format.html { render :action => "edit" }


format.
xml { render :xml => @paper.errors, :status =>
:unprocessable_entity }


end


end


end



# DELETE /papers/1


# DELETE /papers/1.xml


def destroy


@paper = Paper.find(params[:id])


@paper.destroy



respond_to do |format|


format.ht
ml { redirect_to(papers_url) }


format.xml { head :ok }


end


end

end


Code Document

2008


9

WinVictory
-

Confidential


Sources



Practical Rails Projects,
Ap
ress
Pro
Publishing
, 2007



Practical Rails Social Networking Sites,
Apress

Pro

Publishing
, 2007



Rails Solutions Ruby on Rails Made Easy,
FriendsofEd Apress Publishing
, 2007



Ruby on Rails Up and Running,
O’Reilly
, 2006