Class: NHKore::Article
- Inherits:
-
Object
- Object
- NHKore::Article
- Defined in:
- lib/nhkore/article.rb
Instance Attribute Summary collapse
-
#datetime ⇒ Object
Returns the value of attribute datetime.
-
#futsuurl ⇒ Object
Returns the value of attribute futsuurl.
-
#sha256 ⇒ Object
Returns the value of attribute sha256.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
-
#words ⇒ Object
readonly
Returns the value of attribute words.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_word(word, use_freq: false) ⇒ Object
Why does this not look up the kanji/kana only and then update the other kana/kanji part appropriately? - There are some words like 行って.
- #encode_with(coder) ⇒ Object
-
#initialize ⇒ Article
constructor
A new instance of Article.
- #to_s(mini: false) ⇒ Object
Constructor Details
#initialize ⇒ Article
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/nhkore/article.rb', line 25 def initialize super @datetime = nil @futsuurl = nil @sha256 = nil @title = nil @url = nil @words = {} end |
Instance Attribute Details
#datetime ⇒ Object
Returns the value of attribute datetime.
18 19 20 |
# File 'lib/nhkore/article.rb', line 18 def datetime @datetime end |
#futsuurl ⇒ Object
Returns the value of attribute futsuurl.
19 20 21 |
# File 'lib/nhkore/article.rb', line 19 def futsuurl @futsuurl end |
#sha256 ⇒ Object
Returns the value of attribute sha256.
20 21 22 |
# File 'lib/nhkore/article.rb', line 20 def sha256 @sha256 end |
#title ⇒ Object
Returns the value of attribute title.
21 22 23 |
# File 'lib/nhkore/article.rb', line 21 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
22 23 24 |
# File 'lib/nhkore/article.rb', line 22 def url @url end |
#words ⇒ Object (readonly)
Returns the value of attribute words.
23 24 25 |
# File 'lib/nhkore/article.rb', line 23 def words @words end |
Class Method Details
.load_data(_key, hash) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/nhkore/article.rb', line 70 def self.load_data(_key,hash) words = hash[:words] article = Article.new article.datetime = hash[:datetime] article.futsuurl = hash[:futsuurl] article.sha256 = hash[:sha256] article.title = hash[:title] article.url = hash[:url] words&.each do |k,h| k = k.to_s # Change from a symbol article.words[k] = Word.load_data(k,h) end return article end |
Instance Method Details
#add_word(word, use_freq: false) ⇒ Object
Why does this not look up the kanji/kana only and then update the other kana/kanji part appropriately?
-
There are some words like 行って. Without the kana, it’s difficult to determine what kana it should be. Should it be いって or おこなって?
-
Similarly, if we just have いって, should this be 行って or 言って?
-
Therefore, if we only have the kanji or only have the kana, we don’t try to populate the other value.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/nhkore/article.rb', line 43 def add_word(word,use_freq: false) curr_word = words[word.key] if curr_word.nil? words[word.key] = word curr_word = word else curr_word.freq += (use_freq ? word.freq : 1) curr_word.defn = word.defn if word.defn.to_s.length > curr_word.defn.to_s.length curr_word.eng = word.eng if word.eng.to_s.length > curr_word.eng.to_s.length end return curr_word end |
#encode_with(coder) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/nhkore/article.rb', line 59 def encode_with(coder) # Order matters. coder[:datetime] = @datetime.nil? ? @datetime : @datetime.iso8601 coder[:title] = @title coder[:url] = @url.nil? ? nil : @url.to_s coder[:futsuurl] = @futsuurl.nil? ? nil : @futsuurl.to_s coder[:sha256] = @sha256 coder[:words] = @words end |
#to_s(mini: false) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/nhkore/article.rb', line 107 def to_s(mini: false) s = ''.dup s << "'#{@url}':" s << "\n datetime: '#{@datetime}'" s << "\n title: '#{@title}'" s << "\n url: '#{@url}'" s << "\n futsuurl: '#{@futsuurl}'" s << "\n sha256: '#{@sha256}'" if !mini s << "\n words:" @words.each do |_key,word| s << "\n #{word}" end end return s end |