class NHKore::Article

@author Jonathan Bradley Whited @since 0.2.0

Attributes

datetime[R]
futsuurl[R]
sha256[RW]
title[RW]
url[R]
words[R]

Public Class Methods

load_data(key,hash) click to toggle source
# File lib/nhkore/article.rb, line 76
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
new() click to toggle source
Calls superclass method
# File lib/nhkore/article.rb, line 31
def initialize
  super()

  @datetime = nil
  @futsuurl = nil
  @sha256 = nil
  @title = nil
  @url = nil
  @words = {}
end

Public Instance Methods

add_word(word,use_freq: false) click to toggle source

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.

# File lib/nhkore/article.rb, line 49
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
datetime=(value) click to toggle source
# File lib/nhkore/article.rb, line 95
def datetime=(value)
  if value.is_a?(Time)
    @datetime = value
  else
    @datetime = Util.empty_web_str?(value) ? nil : Time.iso8601(value)
  end
end
encode_with(coder) click to toggle source
# File lib/nhkore/article.rb, line 65
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
futsuurl=(value) click to toggle source
# File lib/nhkore/article.rb, line 103
def futsuurl=(value)
  # Don't store URI, store String.
  @futsuurl = value.nil? ? nil : value.to_s
end
to_s(mini: false) click to toggle source
# File lib/nhkore/article.rb, line 113
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
url=(value) click to toggle source
# File lib/nhkore/article.rb, line 108
def url=(value)
  # Don't store URI, store String.
  @url = value.nil? ? nil : value.to_s
end