Sha256: 1632c5e913f21ae7627909acd87661bed3fa456076fc596a8589265f1ecad757
Contents?: true
Size: 1.79 KB
Versions: 2
Compression:
Stored size: 1.79 KB
Contents
#!/usr/bin/ruby # # connection.rb - this file contains the class declarations for the # LinkParser::Connection class. # # == Synopsis # # # == Rcsid # # $Id: connection.rb,v 1.3 2003/06/08 03:53:27 stillflame Exp $ # # == Authors # # Martin Chase <stillflame@FaerieMUD.org> # #:include: COPYRIGHT # #--- # # Please see the file COPYRIGHT for licensing details. # class LinkParser class Connection include Comparable def initialize( conn1, conn2, lword, rword ) raise( ParseError::new( "A connection cannot be formed between two words that do not match: %s and %s" % [ conn1, conn2 ]) ) unless conn1.match(conn2) @name, @subName = conn1.generalize(conn2) @lword = lword @rword = rword @length = rword.position - lword.position end # the major name of the link attr_reader :name # the minor name of the link attr_reader :subName # the index of the word connected to this link on the left attr_reader :lword # the index of the word connected to this link on the right attr_reader :rword # the number of words spanned by this connection attr_reader :length # Hash on the important part - the name and subname. def hash [@name, @subName].hash end # Provide a consistent basis for sorting connections within a linkage to # allow two linkages to be compared. def <=>(other) pos = self.lword.position <=> other.lword.position return pos if pos.nonzero? len = self.length <=> other.length return len if len.nonzero? return self.to_s <=> other.to_s end # Equality based only on the name and subname. def eql?(o) @name == o.name && @subName == o.subName && @length == o.length end # Stringification delegated to the @general connector. def to_s @name + @subName end end # class Connection end # class LinkParser
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rwdeliza-0.03 | lib/linkparser/connection.rb |
rwdeliza-0.05 | lib/linkparser/connection.rb |