Class: NHKore::Entry
- Inherits:
-
Object
- Object
- NHKore::Entry
- Defined in:
- lib/nhkore/entry.rb
Constant Summary collapse
- HYOUKI_SEP =
'・'
Instance Attribute Summary collapse
-
#defns ⇒ Object
readonly
Returns the value of attribute defns.
-
#id ⇒ Object
Returns the value of attribute id.
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.
23 24 25 26 27 28 |
# File 'lib/nhkore/entry.rb', line 23 def initialize super @defns = [] @id = nil end |
Instance Attribute Details
#defns ⇒ Object (readonly)
Returns the value of attribute defns.
20 21 22 |
# File 'lib/nhkore/entry.rb', line 20 def defns @defns end |
#id ⇒ Object
Returns the value of attribute id.
21 22 23 |
# File 'lib/nhkore/entry.rb', line 21 def id @id end |
Class Method Details
.scrape(id, array, missingno: nil, url: nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/nhkore/entry.rb', line 57 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
30 31 32 33 34 35 36 37 |
# File 'lib/nhkore/entry.rb', line 30 def build_defn i = 0 defns = @defns.map do |defn| "#{i += 1})#{defn}" # Japanese parenthesis end return defns.join("\n") end |
#build_hyouki ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/nhkore/entry.rb', line 39 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
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/nhkore/entry.rb', line 73 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 |