Class: Faun::ForumThread
Instance Attribute Summary
Attributes inherited from Section
Instance Method Summary collapse
- #authors ⇒ Object
- #comments ⇒ Object
-
#initialize(id, name, path) ⇒ ForumThread
constructor
A new instance of ForumThread.
- #item_name ⇒ Object
- #title ⇒ Object
- #to_json(*args) ⇒ Object
Methods inherited from Section
Constructor Details
#initialize(id, name, path) ⇒ ForumThread
Returns a new instance of ForumThread.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/faun.rb', line 183 def initialize(id, name, path) @id = id @name = name comments = {} Dir.each_child(path) do |filename| file = File.join(path, filename) next if File.directory?(file) or filename.start_with?('.') or not filename.end_with?('.md') id, , date_string = filename.scan(/^(\d{3})\.(\w+)\.(20\d\d-\d\d-\d\d\.\d\d-\d\d)\.md$/).first id = id.to_i datetime = DateTime.strptime(date_string, "%Y-%m-%d.%H-%M") content = nil Async do begin File.open(file, "r:UTF-8") do |file| generic = Async::IO::Stream.new(file) content = generic.read.force_encoding("UTF-8") end rescue content = "" end end.wait comments[id] = Comment.new(id, , datetime, content) end @items = comments.sort_by { |id, _| id }.to_h end |
Instance Method Details
#authors ⇒ Object
221 222 223 |
# File 'lib/faun.rb', line 221 def @items.values.map(&:author).uniq end |
#comments ⇒ Object
217 218 219 |
# File 'lib/faun.rb', line 217 def comments @items end |
#item_name ⇒ Object
225 226 227 |
# File 'lib/faun.rb', line 225 def item_name "comments" end |
#title ⇒ Object
213 214 215 |
# File 'lib/faun.rb', line 213 def title @name end |
#to_json(*args) ⇒ Object
229 230 231 232 233 234 235 |
# File 'lib/faun.rb', line 229 def to_json(*args) { :id => id, :title => @name, :comments => @items }.to_json end |