class Runoff::Adapters::JsonAdapter

Constants

ENTRY_FORMAT

Public: A format String used to build a single entry.

Public Instance Methods

build_entry(row) click to toggle source

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" ... }
# => "{ "date": "2014-04-18 20:20:12", "user": "first_user", "message": "This is a text" }"
# File lib/runoff/adapters/json_adapter.rb, line 17
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) click to toggle source

Public: Formats the provided data buffer so that it could be writter to

a JSON file.

buffer - An Array containing all the chat entries.

Returns a String

# File lib/runoff/adapters/json_adapter.rb, line 49
def format_file_content(buffer)
  content = buffer.join(",\n")

  "[#{content}]"
end
get_file_name(chatname) click to toggle source

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.json

Returns a valid file name.

# File lib/runoff/adapters/json_adapter.rb, line 39
def get_file_name(chatname)
  parse_chatname(chatname) + '.json'
end

Protected Instance Methods

format_body_xml(xml_content) click to toggle source

Internal: Escapes the message body so that it could be used in a JSON string

xml_content - A String containing the chat message

Examples

format_body_xml 'foo' # => "\"foo\""

Returns a String

# File lib/runoff/adapters/json_adapter.rb, line 66
def format_body_xml(xml_content)
  JSON.generate(xml_content, quirks_mode: true)
end