Class: NHKore::SearchLinks
- Inherits:
-
Object
- Object
- NHKore::SearchLinks
- 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
-
#links ⇒ Object
readonly
Returns the value of attribute links.
Class Method Summary collapse
Instance Method Summary collapse
- #[](url) ⇒ Object
- #add_link(link) ⇒ Object
- #each ⇒ Object
- #encode_with(coder) ⇒ Object
-
#initialize ⇒ SearchLinks
constructor
A new instance of SearchLinks.
- #length ⇒ Object
- #to_s ⇒ Object
Methods included from Fileable
Constructor Details
#initialize ⇒ SearchLinks
Returns a new instance of SearchLinks.
128 129 130 131 132 |
# File 'lib/nhkore/search_link.rb', line 128 def initialize super @links = {} end |
Instance Attribute Details
#links ⇒ Object (readonly)
Returns the value of attribute links.
126 127 128 |
# File 'lib/nhkore/search_link.rb', line 126 def links @links end |
Class Method Details
.build_file(filename) ⇒ Object
119 120 121 |
# File 'lib/nhkore/search_link.rb', line 119 def self.build_file(filename) return File.join(DEFAULT_DIR,filename) end |
.load_data(data, file: nil, **_kargs) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/nhkore/search_link.rb', line 154 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
169 170 171 172 173 174 |
# File 'lib/nhkore/search_link.rb', line 169 def [](url) url = url.url if url.respond_to?(:url) url = url.to_s unless url.nil? return @links[url] end |
#add_link(link) ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'lib/nhkore/search_link.rb', line 134 def add_link(link) url = link.url&.to_s return self if @links.key?(url) @links[url] = link return self end |
#each ⇒ Object
144 145 146 |
# File 'lib/nhkore/search_link.rb', line 144 def each(&) return @links.each(&) end |
#encode_with(coder) ⇒ Object
148 149 150 151 152 |
# File 'lib/nhkore/search_link.rb', line 148 def encode_with(coder) # Order matters. coder[:links] = @links end |
#length ⇒ Object
176 177 178 |
# File 'lib/nhkore/search_link.rb', line 176 def length return @links.length end |
#to_s ⇒ Object
180 181 182 |
# File 'lib/nhkore/search_link.rb', line 180 def to_s return Util.dump_yaml(self) end |