Class: NHKore::Dict

Inherits:
Object
  • Object
show all
Defined in:
lib/nhkore/dict.rb

Overview

Author:

  • Jonathan Bradley Whited

Since:

  • 0.2.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDict

Returns a new instance of Dict.

Since:

  • 0.2.0



24
25
26
27
28
# File 'lib/nhkore/dict.rb', line 24

def initialize
  super()

  @entries = {}
end

Instance Attribute Details

#entriesObject (readonly)

Since:

  • 0.2.0



22
23
24
# File 'lib/nhkore/dict.rb', line 22

def entries
  @entries
end

Class Method Details

.scrape(hash, missingno: nil, url: nil) ⇒ Object

Since:

  • 0.2.0



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

Since:

  • 0.2.0



30
31
32
# File 'lib/nhkore/dict.rb', line 30

def [](id)
  return @entries[id]
end

#[]=(id, entry) ⇒ Object

Since:

  • 0.2.0



34
35
36
# File 'lib/nhkore/dict.rb', line 34

def []=(id,entry)
  @entries[id] = entry
end

#key?(id) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 0.2.0



53
54
55
# File 'lib/nhkore/dict.rb', line 53

def key?(id)
  return @entries.key?(id)
end

#to_sObject

Since:

  • 0.2.0



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