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.
18 19 20 21 22 |
# File 'lib/nhkore/dict.rb', line 18 def initialize super @entries = {} end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
16 17 18 |
# File 'lib/nhkore/dict.rb', line 16 def entries @entries end |
Class Method Details
.scrape(hash, missingno: nil, url: nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/nhkore/dict.rb', line 32 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
24 25 26 |
# File 'lib/nhkore/dict.rb', line 24 def [](id) return @entries[id] end |
#[]=(id, entry) ⇒ Object
28 29 30 |
# File 'lib/nhkore/dict.rb', line 28 def []=(id,entry) @entries[id] = entry end |
#key?(id) ⇒ Boolean
48 49 50 |
# File 'lib/nhkore/dict.rb', line 48 def key?(id) return @entries.key?(id) end |
#to_s ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/nhkore/dict.rb', line 52 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 |