Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Create Api to create document and add,edit,delete text and t

Reply
Thread Tools

Create Api to create document and add,edit,delete text and t

 
 
Krithika San
Guest
Posts: n/a
 
      11-13-2009
Sub: Create Api to create document and add, edit, delete text and
table(add row, modify and delete row)

Can somebody please tell me how to implement this using inheritence /
composition / patterns ?

Thanks,
skrithikaa
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Marnen Laibow-Koser
Guest
Posts: n/a
 
      11-14-2009
Krithika San wrote:
> Sub: Create Api to create document and add, edit, delete text and
> table(add row, modify and delete row)
>
> Can somebody please tell me how to implement this using inheritence /
> composition / patterns ?


Do your own homework. If you're stuck, let us know what you've tried
and what isn't working.

>
> Thanks,
> skrithikaa


Best,
--
Marnen Laibow-Koser
http://www.marnen.org

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Krithika San
Guest
Posts: n/a
 
      11-14-2009
This is what I coded and I need to change so that it accepts the text,
and table rows and columns in a dynamic way.

This was the comments I obtained. Can you please correct the mistake.


Table and Text are not "is-a" DocumentBuilder
It is not clear how TableElt and TextElt contribute to the requirements
The DataTable class (which appears to be how you addressed the Table
requirements) is not related to the DocumentBuilder stuff. In fact, I'm
not sure how to create a document with a working table in it at all
Also, I don't see how to add a Text element to a document

Please put your classes in separate .rb files in the future.
The design document includes a lot of boilerplate text about the
components of an abstract factory, but it is not clear to me how any of
this relates to fulfilling the requirements of the core classes in the
assignment.
The "alter" method should just accept the row/column to "alter" rather
than have to set them prior.


Hope you can help me with this.

class DocumentBuilder
def new_document
end
end

class Table < DocumentBuilder
end

class Text < DocumentBuilder
end

# 2. implementations of specializations

class TableElt < Table
def new_document
puts "I am a word document "
end
end

class TextElt < Text
def new_document
puts "I am a word document"
end
end

# 3. interface for factory (abstract factory)

class DocumentBuilderFactory
def create_doc
end
end

# 4. different factories implementations

class TableFactory < DocumentBuilderFactory
def create_doc
TableElt.new
end
end

class TextFactory < DocumentBuilderFactory
def create_doc
TextElt.new
end
end

class DynamicFactory
def initialize(doc_class)
@doc_class = doc_class
end

def create_doc
@doc_class.new
end
end

# 5. factories manager (optional)

class DocumentBuilderManager
def create_doc_factory(type)
if(type == :Table)
TableFactory.new
elsif(type == :Text)
TextFactory.new
end
end
end

# 6. test

doc_manager = DocumentBuilderManager.new

DocumentBuilder_factory1 = doc_manager.create_doc_factory(:Table)
DocumentBuilder_factory2 = doc_manager.create_doc_factory(:Text)
DocumentBuilder_factory3 = DynamicFactory.new(TableElt)

DocumentBuilder1 = DocumentBuilder_factory1.create_doc
DocumentBuilder2 = DocumentBuilder_factory2.create_doc
DocumentBuilder3 = DocumentBuilder_factory3.create_doc

DocumentBuilder1.new_document
DocumentBuilder2.new_document
DocumentBuilder3.new_document

# creating table entries

class DataTable
attr_accessor :current_line, :current_column
attr_reader :file_name

# A table is basically an array of arrays.
# So start by creating the host array.
def initialize
@table = Array.new
@current_line = 0
@current_column = 0
end

# Allows to add elements into the table
def add_line(*entries)
@table << entries
end

# Alters the content in a table
# (note first line = 0, and first cell = 0)
def alter_current_cell(entry)
@table[@current_line][@current_column] = entry
end

# Deletes a row in a table
def remove_line(line_number)
@table.delete_at(line_number)
end

# Create an output file
def output_to_file(file_name)
@file_name = file_name
create_file
put_data_into_file
end

private
def create_file
File.delete(@file_name) if File.exist?(@file_name)
File.new(@file_name, 'w+')
end

# Add the table info, and close
def put_data_into_file
output_file = File.open(@file_name, 'w+')
for line in @table
output_file.puts line.join(" ")
end
output_file.close
end
end


data_table = DataTable.new
data_table.add_line('Country', 'Animal', 'Fruit')
data_table.add_line('India', ' Tiger ', ' Mango')
data_table.add_line('China', ' Cheeta ', 'Apple')
data_table.add_line('Japan',' Monkey ','Orange')
puts "View display_table.txt to see the contents of the table"
data_table.output_to_file('display_table.txt')
data_table.current_line = 2 # entry in this cell is changed
data_table.current_column = 1 # entry in this cell is changed
data_table.alter_current_cell(' DONKEY ') # entry in this cell is
changed to DONKEY
puts "View modified_ouput.txt to see modified content"
data_table.output_to_file('modified_ouput.txt')
data_table.current_line = 1
data_table.current_column = 2
data_table.remove_line(1)
puts "View output_without_line_1.txt to see the final output with the
removal of row 1"
data_table.output_to_file('output_without_line_1.t xt')






Marnen Laibow-Koser wrote:
> Krithika San wrote:
>> Sub: Create Api to create document and add, edit, delete text and
>> table(add row, modify and delete row)
>>
>> Can somebody please tell me how to implement this using inheritence /
>> composition / patterns ?

>
> Do your own homework. If you're stuck, let us know what you've tried
> and what isn't working.
>
>>
>> Thanks,
>> skrithikaa

>
> Best,
> --
> Marnen Laibow-Koser
> http://www.marnen.org
>


--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Marnen Laibow-Koser
Guest
Posts: n/a
 
      11-14-2009
Krithika San wrote:
> This is what I coded and I need to change so that it accepts the text,
> and table rows and columns in a dynamic way.
>
> This was the comments I obtained. Can you please correct the mistake.
>


No! The comments provide all the information you need for you to do
your own correcting. Try it yourself first. If you're stuck, read a
reference book, search the Web, or ask your professor. If you have a
specific question to ask, most of us here will be happy to answer it,
but simply dumping a homework assignment that you obviously haven't even
*tried* to work on is not OK.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
.Net Profiler API in 64 bit windows -FunctionMapper callback API =?Utf-8?B?TGVv?= Windows 64bit 0 09-05-2007 06:10 PM
Profiling API or Membership API John123 ASP .Net 0 10-20-2006 03:18 PM
Calling the C API from Python and Python program from same C API -bidirectional Praveen, Tayal (IE10) Python 0 03-17-2005 06:33 AM
Change text color for one document.write but not color of all text? kroger@princeton.edu Javascript 7 02-02-2005 01:23 PM
What API replaces the unlock API that existed in gcc 2.9.3? Shlomo Anglister C++ 1 08-02-2004 06:50 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57