Class: Faun::Post
Instance Attribute Summary collapse
Attributes inherited from Section
#items, #name
Instance Method Summary
collapse
Methods inherited from Section
#each, #each_key, #each_value
Constructor Details
#initialize(id, name, path) ⇒ Post
Returns a new instance of Post.
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/faun.rb', line 139
def initialize(id, name, path)
super(id, name, path, ForumThread)
Async do
File.open(File.join(path, "latest.md"), "r:UTF-8") do |file|
generic = Async::IO::Stream.new(file)
lines = Async::IO::Protocol::Line.new(generic).each_line
lines.next
meta = lines.take_while { |line| line.strip != "---" }.join("\n")
@meta = YAML.load(meta)
@meta["written"] = DateTime.strptime(@meta["written"], "%Y-%m-%d %H:%M")
@content = generic.read.force_encoding("UTF-8")
end
end.wait
end
|
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
137
138
139
|
# File 'lib/faun.rb', line 137
def content
@content
end
|
#id ⇒ Object
Returns the value of attribute id.
137
138
139
|
# File 'lib/faun.rb', line 137
def id
@id
end
|
Returns the value of attribute meta.
137
138
139
|
# File 'lib/faun.rb', line 137
def meta
@meta
end
|
Instance Method Details
#author ⇒ Object
159
160
161
|
# File 'lib/faun.rb', line 159
def author
@meta["author"]
end
|
#item_name ⇒ Object
167
168
169
|
# File 'lib/faun.rb', line 167
def item_name
"threads"
end
|
#threads ⇒ Object
163
164
165
|
# File 'lib/faun.rb', line 163
def threads
@items
end
|
#title ⇒ Object
155
156
157
|
# File 'lib/faun.rb', line 155
def title
@name
end
|
#to_json(*args) ⇒ Object
171
172
173
174
175
176
177
178
179
|
# File 'lib/faun.rb', line 171
def to_json(*args)
json = @meta.clone
json.merge!(
id: @id,
content: @content,
threads: @items
)
json.to_json(*args)
end
|