Class: Eiwa::Tag::Character

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

Instance Attribute Summary collapse

Attributes inherited from Any

#characters, #parent, #tag_name

Instance Method Summary collapse

Methods inherited from Any

#add_characters, #end_self, #start, #to_s

Instance Attribute Details

#freqObject (readonly)

Returns the value of attribute freq.



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

def freq
  @freq
end

#gradeObject (readonly)

Returns the value of attribute grade.



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

def grade
  @grade
end

#jlptObject (readonly)

Returns the value of attribute jlpt.



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

def jlpt
  @jlpt
end

#kunyomiObject (readonly)

Returns the value of attribute kunyomi.



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

def kunyomi
  @kunyomi
end

#meaningsObject (readonly)

Returns the value of attribute meanings.



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

def meanings
  @meanings
end

#onyomiObject (readonly)

Returns the value of attribute onyomi.



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

def onyomi
  @onyomi
end

#stroke_countObject (readonly)

Returns the value of attribute stroke_count.



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

def stroke_count
  @stroke_count
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Instance Method Details

#end_child(child) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/eiwa/tag/character.rb', line 8

def end_child(child)
  if child.tag_name == "literal"
    @text = child.text
  elsif child.tag_name == "reading_meaning"
    @onyomi = child.rmgroup.items.select { |item| item.name == "reading" && item.attrs["r_type"] == "ja_on" }.map(&:text)
    @kunyomi = child.rmgroup.items.select { |item| item.name == "reading" && item.attrs["r_type"] == "ja_kun" }.map(&:text)
    @meanings = child.rmgroup.items.select { |item| item.name == "meaning" && (item.attrs["m_lang"].nil? || item.attrs["m_lang"] == "en") }.map(&:text)
  elsif child.tag_name == "misc"
    @grade = child["grade"]&.to_i
    @stroke_count = child["stroke_count"]&.to_i
    @freq = child["freq"]&.to_i
    @jlpt = child["jlpt"]&.to_i
  end
end