Class: NHKore::Missingno

Inherits:
Object
  • Object
show all
Defined in:
lib/nhkore/missingno.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Missingno

Returns a new instance of Missingno.

Parameters:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/nhkore/missingno.rb', line 21

def initialize(data)
  super()

  @kanas = {}
  @kanjis = {}

  # News?
  if data.respond_to?(:articles)
    add_news(data)
  # Article?
  elsif data.respond_to?(:words)
    add_article(data)
  else
    add_words(data)
  end
end

Instance Attribute Details

#kanasObject (readonly)

Returns the value of attribute kanas.



17
18
19
# File 'lib/nhkore/missingno.rb', line 17

def kanas
  @kanas
end

#kanjisObject (readonly)

Returns the value of attribute kanjis.



18
19
20
# File 'lib/nhkore/missingno.rb', line 18

def kanjis
  @kanjis
end

Instance Method Details

#add_article(article) ⇒ Object



38
39
40
# File 'lib/nhkore/missingno.rb', line 38

def add_article(article)
  add_words(article.words.values)
end

#add_news(news) ⇒ Object



42
43
44
45
46
# File 'lib/nhkore/missingno.rb', line 42

def add_news(news)
  news.articles.each_value do |article|
    add_article(article)
  end
end

#add_words(words) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/nhkore/missingno.rb', line 48

def add_words(words)
  words.each do |word|
    # We only want ones that are both filled in because
    #   Word.scrape_ruby_tag() will raise an error if either is empty.
    next if Util.empty_web_str?(word.kana) || Util.empty_web_str?(word.kanji)

    if !kanas.key?(word.kana)
      kanas[word.kana] = word
    end

    if !kanjis.key?(word.kanji)
      kanjis[word.kanji] = word
    end
  end
end

#kana_from_kanji(kanji) ⇒ Object



64
65
66
67
68
# File 'lib/nhkore/missingno.rb', line 64

def kana_from_kanji(kanji)
  word = @kanjis[kanji]

  return word&.kana
end

#kanji_from_kana(kana) ⇒ Object



70
71
72
73
74
# File 'lib/nhkore/missingno.rb', line 70

def kanji_from_kana(kana)
  word = @kanas[kana]

  return word&.kanji
end