class ActivityProvider::LRS::Statement

Public Class Methods

convert_json(statement_json) click to toggle source

Converting JSON to Hash for easy using Virtus

# File lib/activity_provider/lrs/statement.rb, line 42
def self.convert_json(statement_json)
  statement_hash = JSON.parse(statement_json)
  actor = statement_hash['actor']
  if actor
    identifier = {}
    identifier['account'] = actor.delete('account')
    actor['identifier'] = identifier
  end
  verb = statement_hash['verb']
  if verb
    verb_name = verb['id'].match(%r{\/(\w*)$})
    verb['verb'] = verb_name[1]
  end

  statement_hash['actor'] = actor
  statement_hash['verb'] = verb
  statement_hash
end
find(id) click to toggle source
# File lib/activity_provider/lrs/statement.rb, line 37
def self.find(id)
  ActivityProvider.fetch_statement(id)
end
new(*args) click to toggle source
Calls superclass method
# File lib/activity_provider/lrs/statement.rb, line 16
def initialize(*args)
  if args.first.is_a?(String)
    super(Statement.convert_json(args.first))
  else
    super(*args)
  end
end

Public Instance Methods

as_json(*_args) click to toggle source
# File lib/activity_provider/lrs/statement.rb, line 32
def as_json(*_args)
  validate!
  dump_attributes(%i(actor verb object context result))
end
save() click to toggle source
# File lib/activity_provider/lrs/statement.rb, line 24
def save
  if @id
    ActivityProvider::LRS::Client.new.send_statement(self)
  else
    ActivityProvider::LRS::Client.new.send_statements([self])
  end
end