Class: Eiwa::Tag::CrossReference

Inherits:
Any
  • Object
show all
Defined in:
lib/eiwa/tag/cross_reference.rb

Instance Attribute Summary collapse

Attributes inherited from Any

#characters, #parent, #tag_name

Instance Method Summary collapse

Methods inherited from Any

#add_characters, #end_child, #start, #to_s

Constructor Details

#initialize(text: nil, reading: nil, sense_ordinal: nil) ⇒ CrossReference

Returns a new instance of CrossReference.



6
7
8
9
10
# File 'lib/eiwa/tag/cross_reference.rb', line 6

def initialize(text: nil, reading: nil, sense_ordinal: nil)
  @text = text
  @reading = reading
  @sense_ordinal = sense_ordinal
end

Instance Attribute Details

#readingObject (readonly)

Returns the value of attribute reading.



4
5
6
# File 'lib/eiwa/tag/cross_reference.rb', line 4

def reading
  @reading
end

#sense_ordinalObject (readonly)

Returns the value of attribute sense_ordinal.



4
5
6
# File 'lib/eiwa/tag/cross_reference.rb', line 4

def sense_ordinal
  @sense_ordinal
end

#textObject (readonly)

Returns the value of attribute text.



4
5
6
# File 'lib/eiwa/tag/cross_reference.rb', line 4

def text
  @text
end

Instance Method Details

#end_selfObject



12
13
14
15
16
17
# File 'lib/eiwa/tag/cross_reference.rb', line 12

def end_self
  parts = @characters.split("・")
  @text = parts.first
  @reading = parts[1..-1].find { |part| /[^0-9]/.match(part) }
  @sense_ordinal = parts.find { |part| /^[0-9]+$/.match(part) }&.to_i
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/eiwa/tag/cross_reference.rb', line 19

def eql?(other)
  @text == other.text &&
    @reading == other.reading &&
    @sense_ordinal == other.sense_ordinal
end

#hashObject



26
27
28
# File 'lib/eiwa/tag/cross_reference.rb', line 26

def hash
  @text.hash + @reading.hash + @sense_ordinal.hash
end