Class: NHKore::Entry
- Inherits:
-
Object
- Object
- NHKore::Entry
- Defined in:
- lib/nhkore/entry.rb
Overview
Constant Summary collapse
- HYOUKI_SEP =
'・'
Instance Attribute Summary collapse
- #defns ⇒ Object readonly
- #id ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
- #build_defn ⇒ Object
- #build_hyouki ⇒ Object
-
#initialize ⇒ Entry
constructor
A new instance of Entry.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Entry
Returns a new instance of Entry.
27 28 29 30 31 32 |
# File 'lib/nhkore/entry.rb', line 27 def initialize super() @defns = [] @id = nil end |
Instance Attribute Details
#defns ⇒ Object (readonly)
24 25 26 |
# File 'lib/nhkore/entry.rb', line 24 def defns @defns end |
#id ⇒ Object
25 26 27 |
# File 'lib/nhkore/entry.rb', line 25 def id @id end |
Class Method Details
.scrape(id, array, missingno: nil, url: nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/nhkore/entry.rb', line 63 def self.scrape(id,array,missingno: nil,url: nil) entry = Entry.new entry.id = Util.unspace_web_str(id.to_s).downcase return nil if entry.id.empty? array.each do |hash| defn = Defn.scrape(hash,missingno: missingno,url: url) entry.defns << defn unless defn.nil? end return nil if entry.defns.empty? return entry end |
Instance Method Details
#build_defn ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/nhkore/entry.rb', line 34 def build_defn defns = [] i = 0 @defns.each do |defn| defns << "#{i += 1})#{defn}" # Japanese parenthesis end return defns.join("\n") end |
#build_hyouki ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/nhkore/entry.rb', line 45 def build_hyouki # Since Ruby v1.9, Hash preserves order. # Ruby v2.7 doc for Set still says no guarantee of order, so don't use. hyoukis = {} @defns.each do |defn| defn.hyoukis.each do |hyouki| hyouki = hyouki.chomp(HYOUKI_SEP) next if hyouki.empty? hyoukis[hyouki] = true end end return hyoukis.keys.join(HYOUKI_SEP) end |
#to_s ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/nhkore/entry.rb', line 79 def to_s s = ''.dup return s if @defns.empty? hyouki = build_hyouki s << "#{hyouki}\n" unless Util.empty_web_str?(hyouki) s << build_defn return s end |