mirror of https://github.com/Calamitous/iris.git
Adding corpus functionality
This commit is contained in:
parent
48b82574dc
commit
2fb033d840
42
iris.rb
42
iris.rb
|
@ -32,8 +32,8 @@ class Config
|
||||||
return @@loaded_config = JSON.load(filepath)
|
return @@loaded_config = JSON.load(filepath)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.load_corpus
|
def self.find_files
|
||||||
@@message_corpus ||= (`ls /home/**/.iris.config.json`).split("\n")
|
@@message_corpus ||= (`ls /home/**/.iris.messages`).split("\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -56,6 +56,30 @@ class IrisFile
|
||||||
new_message
|
new_message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.write_corpus(corpus)
|
||||||
|
File.write(Config::MESSAGE_FILE, corpus)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Corpus
|
||||||
|
def self.load
|
||||||
|
@@corpus = Config.find_files.map { |filepath| IrisFile.load_messages(filepath) }.flatten.sort_by(&:timestamp)
|
||||||
|
@@topics = @@corpus.select{ |m| m.parent == nil }
|
||||||
|
@@my_corpus = IrisFile.load_messages
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.all
|
||||||
|
@@corpus
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.topics
|
||||||
|
@@topics
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.mine
|
||||||
|
@@my_corpus
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Message
|
class Message
|
||||||
|
@ -99,6 +123,14 @@ class Message
|
||||||
@errors.empty?
|
@errors.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def save!
|
||||||
|
new_corpus = Corpus.mine << self
|
||||||
|
p new_corpus
|
||||||
|
p new_corpus.to_json
|
||||||
|
IrisFile.write_corpus(new_corpus.to_json)
|
||||||
|
Corpus.load
|
||||||
|
end
|
||||||
|
|
||||||
def hash(payload = nil)
|
def hash(payload = nil)
|
||||||
payload ||= unconfirmed_payload.to_json
|
payload ||= unconfirmed_payload.to_json
|
||||||
Base64.encode64(Digest::SHA1.digest(payload))
|
Base64.encode64(Digest::SHA1.digest(payload))
|
||||||
|
@ -108,7 +140,8 @@ class Message
|
||||||
parent.nil?
|
parent.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_json
|
def to_json(*args)
|
||||||
|
p args
|
||||||
{
|
{
|
||||||
hash: hash,
|
hash: hash,
|
||||||
edit_hash: edit_hash,
|
edit_hash: edit_hash,
|
||||||
|
@ -126,3 +159,6 @@ class Message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Corpus.load
|
||||||
|
puts "#{Config::AUTHOR}>"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue