Class: Mess::Chat
- Inherits:
-
Object
- Object
- Mess::Chat
- Defined in:
- lib/mess/chat.rb
Instance Attribute Summary collapse
-
#msgs ⇒ Object
readonly
Returns the value of attribute msgs.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#usrs ⇒ Object
readonly
Returns the value of attribute usrs.
Instance Method Summary collapse
-
#initialize(path) ⇒ Chat
constructor
A new instance of Chat.
- #size ⇒ Object
Constructor Details
#initialize(path) ⇒ Chat
Returns a new instance of Chat.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mess/chat.rb', line 16 def initialize path @path = File.(path) # make sure the path is somewhat valid raise ChatInvalidError unless File.exists? @path # maybe given a file within the directory instead? -> scope out @path = File.dirname(@path) if File.file? @path # prepare data buffers @title = nil @usrs = nil @msgs = Array.new # either .json or .html -> message_1.ext to find out the format = Dir["#@path/message_1\\.*"] raise ChatInvalidError unless .one? = .first extension = File.extname() extension = extension[1..-1] # remove the dot in .ext # reference the get_extension function get = method("get_#{extension}") # iterate through message_X.ext and use get method to parse the files # do it chronologically -> descending X for messenger (reeee) total = Dir["#@path/message_*\\.#{extension}"].size total.downto(1) do |i| file = "#@path/message_#{i}.#{extension}" get.call(file) #rescue raise ChatInvalidError end @title = '*you*' if @title.nil? or @title.empty? @msgs.sort_by!(&:time) @usrs.sort! end |
Instance Attribute Details
#msgs ⇒ Object (readonly)
Returns the value of attribute msgs.
14 15 16 |
# File 'lib/mess/chat.rb', line 14 def msgs @msgs end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/mess/chat.rb', line 14 def path @path end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
14 15 16 |
# File 'lib/mess/chat.rb', line 14 def title @title end |
#usrs ⇒ Object (readonly)
Returns the value of attribute usrs.
14 15 16 |
# File 'lib/mess/chat.rb', line 14 def usrs @usrs end |
Instance Method Details
#size ⇒ Object
53 54 55 |
# File 'lib/mess/chat.rb', line 53 def size @msgs.size end |