Class: Runoff::Adapters::TxtAdapter
- Defined in:
- lib/runoff/adapters/txt_adapter.rb
Constant Summary collapse
- ENTRY_FORMAT =
Public: A format String used to build a single entry.
"[%s] %s: %s"
Instance Method Summary collapse
-
#build_entry(row) ⇒ Object
Public: Builds a single entry.
-
#format_file_content(buffer) ⇒ Object
Public: Formats the provided data buffer so that it could be writter to a text file.
-
#get_file_name(chatname) ⇒ Object
Public: returns a file name.
-
#parse_chatname(raw_chatname) ⇒ Object
Public: Parses a chatname into a human readable name.
Instance Method Details
#build_entry(row) ⇒ Object
Public: Builds a single entry.
row - An Array containing a single row of data from the database.
Examples
build_entry { chatname: "#first_user/$second_user;d3d86c6b0e3b8320" ... }
# => "[2014-04-18 20:20:12] first_user: This is a text"
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/runoff/adapters/txt_adapter.rb', line 15 def build_entry(row) formated_data = [] # NOTE: The first column in the array is used for the grouping by id and # the second is used for the filename. Runoff::COLUMNS[2..-1].each do |column| formated_data << send("format_#{column}", row[column]) end ENTRY_FORMAT % formated_data end |
#format_file_content(buffer) ⇒ Object
Public: Formats the provided data buffer so that it could be writter to
a text file.
buffer - An Array containing all the chat entries.
Returns a String
64 65 66 |
# File 'lib/runoff/adapters/txt_adapter.rb', line 64 def format_file_content(buffer) buffer.join("\n") end |
#get_file_name(chatname) ⇒ Object
Public: returns a file name.
chatname - A String with a Skype chatname
Examples
get_file_name "#first_user/$second_user;d3d86c6b0e3b8320"
# => first_user_second_user.txt
Returns a valid file name.
37 38 39 |
# File 'lib/runoff/adapters/txt_adapter.rb', line 37 def get_file_name(chatname) parse_chatname(chatname) + '.txt' end |
#parse_chatname(raw_chatname) ⇒ Object
Public: Parses a chatname into a human readable name.
raw_chatname - A String with a Skype chatname.
Examples
parse_chatname "#first_user/$second_user;d3d86c6b0e3b8320"
# => first_user_second_user
Returns a valid name.
51 52 53 54 55 56 |
# File 'lib/runoff/adapters/txt_adapter.rb', line 51 def parse_chatname(raw_chatname) pattern = /^#(.*)\/\$(.*);.*$/ parts = raw_chatname.match(pattern).captures parts.reject(&:empty?).join('_') end |