DLLNode Gem Gem Version

Defines and implements a Doubly Linked List Node Abstract Data Structure and DLLNode class. A Node subclass. A DLLNode has a data attribute, a front attribute, and a back attribute. There is a DLLNode class and a DLLNodeHelper module. The class and the module contain eleven methods. Six methods are public DLLNode instance methods, three are private DLLNode instance methods, and two are helper methods.

Installation

Add this line to your application's Gemfile:

gem 'doubly_linked_list_node', '1.0.2'

And then execute:

$ bundle

Or install it yourself as:

$ gem install doubly_linked_list_node 

Usage

The DLLNode class subclasses Node, and represents a Doubly Linked List Node Abstract Data Structure. The data attribute stores the node's data, the front attribute refers the proceeding node, and the back attribute refers the preceding node. The attributes accept particular types. Operating unacceptable types raises errors.

Assumptions

  • DLLNode's acceptable data types are type String, Fixnum, Float, Complex, Time, Symbol, Bignum, and NilClass. All other types are unacceptable data types and raise errors.
  • The front and back attributes' acceptable objects are NilClass objects, and DLLNode objects. All other object type arguments raise errors.

Public instance methods

There are six public instance methods.

initialize(data_argument = nil, back_argument = nil, front_argument = nil)

The constructor. Takes three arguments. The arguments initialize the data, back, and front attributes. Calls the corresponding attribute setter methods. The argument default values are all nil.

data()

Getter method. Gets the data attribute object reference and returns it.

back()

Getter method. Gets the back attribute's DLLNode object reference and returns it.

front()

Getter method. Gets the DLLNode object the front attribute refers and returns it.

==(node)

The equality operator. Returns true in the case self and the argued node's attributes refer the same objects. Returns false otherwise. In the case the argument is any type excluding DLLNode, raises an ArgumentError.

deeply_dup()

Deeply copies self and returns the duplicate. Untested. Use carefully.

Private instance methods

There are three private instance methods.

data=(data_object)

Setter method. Sets the data attribute the argued object. Calls the verify_data_type(data_object) helper method, passing the argued data object. In the case the data object is an unacceptable type, raises an ArgumentError.

back=(node)

Setter method. Sets the back attribute the argued node's reference.

front=(node)

Setter method. Sets the front attribute the argued DLLNode reference.

Helper methods

There are two helper methods.

verify_data_type(data_object)

Boolean method. In the case the argument's type is unacceptable, raises an ArgumentError. Otherwise, returns true.

verify_bfnode_type(node)

Boolean method. In the case the argument is a DLLNode, returns true. Otherwise raises an ArgumentError.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Testing

The class methods and the helper methods were basically tested. Further testing is necessary. One method, the deeply_dup() public instance method was untested.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/scientist8202/DLLNode. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the DLLNode project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.