Class: NHKore::SearchLinks
- Inherits:
-
Object
- Object
- NHKore::SearchLinks
- Includes:
- Fileable
- Defined in:
- lib/nhkore/search_link.rb
Overview
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
Class Method Summary collapse
Instance Method Summary collapse
- #[](url) ⇒ Object
- #add_link(link) ⇒ Object
- #each(&block) ⇒ 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.
138 139 140 141 142 |
# File 'lib/nhkore/search_link.rb', line 138 def initialize super() @links = {} end |
Instance Attribute Details
#links ⇒ Object (readonly)
136 137 138 |
# File 'lib/nhkore/search_link.rb', line 136 def links @links end |
Class Method Details
.build_file(filename) ⇒ Object
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
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
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 |
#add_link(link) ⇒ Object
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
154 155 156 |
# File 'lib/nhkore/search_link.rb', line 154 def each(&block) return @links.each(&block) end |
#encode_with(coder) ⇒ Object
158 159 160 161 162 |
# File 'lib/nhkore/search_link.rb', line 158 def encode_with(coder) # Order matters. coder[:links] = @links end |
#length ⇒ Object
186 187 188 |
# File 'lib/nhkore/search_link.rb', line 186 def length return @links.length end |