Class: LinkParser::Connection
- Includes:
- Comparable
- Defined in:
- lib/linkparser/connection.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
the number of words spanned by this connection.
-
#lword ⇒ Object
readonly
the index of the word connected to this link on the left.
-
#name ⇒ Object
readonly
the major name of the link.
-
#rword ⇒ Object
readonly
the index of the word connected to this link on the right.
-
#subName ⇒ Object
readonly
the minor name of the link.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Provide a consistent basis for sorting connections within a linkage to allow two linkages to be compared.
-
#eql?(o) ⇒ Boolean
Equality based only on the name and subname.
-
#hash ⇒ Object
Hash on the important part - the name and subname.
-
#initialize(conn1, conn2, lword, rword) ⇒ Connection
constructor
A new instance of Connection.
-
#to_s ⇒ Object
Stringification delegated to the @general connector.
Constructor Details
#initialize(conn1, conn2, lword, rword) ⇒ Connection
Returns a new instance of Connection.
28 29 30 31 32 33 34 35 36 |
# File 'lib/linkparser/connection.rb', line 28 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 |
Instance Attribute Details
#length ⇒ Object (readonly)
the number of words spanned by this connection
51 52 53 |
# File 'lib/linkparser/connection.rb', line 51 def length @length end |
#lword ⇒ Object (readonly)
the index of the word connected to this link on the left
45 46 47 |
# File 'lib/linkparser/connection.rb', line 45 def lword @lword end |
#name ⇒ Object (readonly)
the major name of the link
39 40 41 |
# File 'lib/linkparser/connection.rb', line 39 def name @name end |
#rword ⇒ Object (readonly)
the index of the word connected to this link on the right
48 49 50 |
# File 'lib/linkparser/connection.rb', line 48 def rword @rword end |
#subName ⇒ Object (readonly)
the minor name of the link
42 43 44 |
# File 'lib/linkparser/connection.rb', line 42 def subName @subName end |
Instance Method Details
#<=>(other) ⇒ Object
Provide a consistent basis for sorting connections within a linkage to allow two linkages to be compared.
60 61 62 63 64 65 66 |
# File 'lib/linkparser/connection.rb', line 60 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 |
#eql?(o) ⇒ Boolean
Equality based only on the name and subname.
69 70 71 72 73 |
# File 'lib/linkparser/connection.rb', line 69 def eql?(o) @name == o.name && @subName == o.subName && @length == o.length end |
#hash ⇒ Object
Hash on the important part - the name and subname.
54 55 56 |
# File 'lib/linkparser/connection.rb', line 54 def hash [@name, @subName].hash end |
#to_s ⇒ Object
Stringification delegated to the @general connector.
76 77 78 |
# File 'lib/linkparser/connection.rb', line 76 def to_s @name + @subName end |