Class: NHKore::SearchLinks

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

Overview

Author:

  • Jonathan Bradley Whited

Since:

  • 0.2.0

Constant Summary collapse

DEFAULT_DIR =

Since:

  • 0.2.0

Util::CORE_DIR
DEFAULT_FUTSUU_FILENAME =

Since:

  • 0.2.0

'links_nhk_news_web_regular.yml'
DEFAULT_YASASHII_FILENAME =

Since:

  • 0.2.0

'links_nhk_news_web_easy.yml'
DEFAULT_FUTSUU_FILE =

Since:

  • 0.2.0

build_file(DEFAULT_FUTSUU_FILENAME)
DEFAULT_YASASHII_FILE =

Since:

  • 0.2.0

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.

Since:

  • 0.2.0



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

def initialize
  super()

  @links = {}
end

Instance Attribute Details

Since:

  • 0.2.0



136
137
138
# File 'lib/nhkore/search_link.rb', line 136

def links
  @links
end

Class Method Details

.build_file(filename) ⇒ Object

Since:

  • 0.2.0



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

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

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

Since:

  • 0.2.0



164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/nhkore/search_link.rb', line 164

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

Since:

  • 0.2.0



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

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

  return @links[url]
end

Since:

  • 0.2.0



144
145
146
147
148
149
150
151
152
# File 'lib/nhkore/search_link.rb', line 144

def add_link(link)
  url = link.url.nil? ? nil : link.url.to_s

  return self if @links.key?(url)

  @links[url] = link

  return self
end

#each(&block) ⇒ Object

Since:

  • 0.2.0



154
155
156
# File 'lib/nhkore/search_link.rb', line 154

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

#encode_with(coder) ⇒ Object

Since:

  • 0.2.0



158
159
160
161
162
# File 'lib/nhkore/search_link.rb', line 158

def encode_with(coder)
  # Order matters.

  coder[:links] = @links
end

#lengthObject

Since:

  • 0.2.0



186
187
188
# File 'lib/nhkore/search_link.rb', line 186

def length
  return @links.length
end

#to_sObject

Since:

  • 0.2.0



190
191
192
# File 'lib/nhkore/search_link.rb', line 190

def to_s
  return Util.dump_yaml(self)
end