Class: NHKore::Dict
- Inherits:
-
Object
- Object
- NHKore::Dict
- Defined in:
- lib/nhkore/dict.rb
Overview
Instance Attribute Summary collapse
- #entries ⇒ Object readonly
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.
24 25 26 27 28 |
# File 'lib/nhkore/dict.rb', line 24 def initialize super() @entries = {} end |
Instance Attribute Details
#entries ⇒ Object (readonly)
22 23 24 |
# File 'lib/nhkore/dict.rb', line 22 def entries @entries end |
Class Method Details
.scrape(hash, missingno: nil, url: nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/nhkore/dict.rb', line 38 def self.scrape(hash,missingno: nil,url: nil) dict = Dict.new hash.each do |id,array| 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
30 31 32 |
# File 'lib/nhkore/dict.rb', line 30 def [](id) return @entries[id] end |
#[]=(id, entry) ⇒ Object
34 35 36 |
# File 'lib/nhkore/dict.rb', line 34 def []=(id,entry) @entries[id] = entry end |
#key?(id) ⇒ Boolean
53 54 55 |
# File 'lib/nhkore/dict.rb', line 53 def key?(id) return @entries.key?(id) end |
#to_s ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/nhkore/dict.rb', line 57 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 |