Class: NHKore::Dict
- Inherits:
-
Object
- Object
- NHKore::Dict
- Defined in:
- lib/nhkore/dict.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Class Method Summary collapse
Instance Method Summary collapse
- #[](id) ⇒ Object
- #[]=(id, entry) ⇒ Object
-
#initialize ⇒ Dict
constructor
A new instance of Dict.
- #key?(id) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Dict
Returns a new instance of Dict.
20 21 22 23 24 |
# File 'lib/nhkore/dict.rb', line 20 def initialize super @entries = {} end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
18 19 20 |
# File 'lib/nhkore/dict.rb', line 18 def entries @entries end |
Class Method Details
.scrape(hash, missingno: nil, url: nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/nhkore/dict.rb', line 34 def self.scrape(hash,missingno: nil,url: nil) dict = Dict.new hash.each do |id,array| id = id.to_s.strip.downcase # 'RSHOK-K-003806', '0000' entry = Entry.scrape(id,array,missingno: missingno,url: url) next if entry.nil? raise ScrapeError,"duplicate ID[#{id}] at URL[#{url}] in hash[#{hash}]" if dict.key?(id) dict[id] = entry end return dict end |
Instance Method Details
#[](id) ⇒ Object
26 27 28 |
# File 'lib/nhkore/dict.rb', line 26 def [](id) return @entries[id] end |
#[]=(id, entry) ⇒ Object
30 31 32 |
# File 'lib/nhkore/dict.rb', line 30 def []=(id,entry) @entries[id] = entry end |
#key?(id) ⇒ Boolean
50 51 52 |
# File 'lib/nhkore/dict.rb', line 50 def key?(id) return @entries.key?(id) end |
#to_s ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/nhkore/dict.rb', line 54 def to_s s = ''.dup @entries.each do |id,entry| s << "#{id}:\n" s << " #{entry.to_s.gsub("\n","\n ").rstrip}\n" end return s end |