Class: NHKore::SearchLinks

Inherits:
Object
  • Object
show all
Includes:
Fileable
Defined in:
lib/nhkore/search_link.rb

Constant Summary collapse

DEFAULT_DIR =
Util::CORE_DIR
DEFAULT_FUTSUU_FILENAME =
'links_nhk_news_web_regular.yml'
DEFAULT_YASASHII_FILENAME =
'links_nhk_news_web_easy.yml'
DEFAULT_FUTSUU_FILE =
build_file(DEFAULT_FUTSUU_FILENAME)
DEFAULT_YASASHII_FILE =
build_file(DEFAULT_YASASHII_FILENAME)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Fileable

included, #save_file

Constructor Details

#initializeSearchLinks

Returns a new instance of SearchLinks.



130
131
132
133
134
# File 'lib/nhkore/search_link.rb', line 130

def initialize
  super

  @links = {}
end

Instance Attribute Details

Returns the value of attribute links.



128
129
130
# File 'lib/nhkore/search_link.rb', line 128

def links
  @links
end

Class Method Details

.build_file(filename) ⇒ Object



121
122
123
# File 'lib/nhkore/search_link.rb', line 121

def self.build_file(filename)
  return File.join(DEFAULT_DIR,filename)
end

.load_data(data, file: nil, **kargs) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/nhkore/search_link.rb', line 156

def self.load_data(data,file: nil,**kargs)
  data = Util.load_yaml(data,file: file)

  links = data[:links]

  slinks = SearchLinks.new

  links&.each() do |key,hash|
    key = key.to_s unless key.nil?
    slinks.links[key] = SearchLink.load_data(key,hash)
  end

  return slinks
end

Instance Method Details

#[](url) ⇒ Object



171
172
173
174
175
176
# File 'lib/nhkore/search_link.rb', line 171

def [](url)
  url = url.url if url.respond_to?(:url)
  url = url.to_s unless url.nil?

  return @links[url]
end


136
137
138
139
140
141
142
143
144
# File 'lib/nhkore/search_link.rb', line 136

def add_link(link)
  url = link.url&.to_s

  return self if @links.key?(url)

  @links[url] = link

  return self
end

#each(&block) ⇒ Object



146
147
148
# File 'lib/nhkore/search_link.rb', line 146

def each(&block)
  return @links.each(&block)
end

#encode_with(coder) ⇒ Object



150
151
152
153
154
# File 'lib/nhkore/search_link.rb', line 150

def encode_with(coder)
  # Order matters.

  coder[:links] = @links
end

#lengthObject



178
179
180
# File 'lib/nhkore/search_link.rb', line 178

def length
  return @links.length
end

#to_sObject



182
183
184
# File 'lib/nhkore/search_link.rb', line 182

def to_s
  return Util.dump_yaml(self)
end