Skip to content

Commit

Permalink
Merge pull request #27 from Hipjea/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Hipjea authored Sep 5, 2024
2 parents 7e8f69b + 7a6253b commit c150304
Show file tree
Hide file tree
Showing 16 changed files with 294 additions and 28 deletions.
6 changes: 6 additions & 0 deletions app/helpers/rails_xapi/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# frozen_string_literal: true

module RailsXapi
module ApplicationHelper
# Output the duration ISO 8601 in minutes.
def duration_to_minutes(duration)
sprintf("%.2f", ActiveSupport::Duration.parse(duration)&.in_minutes)
end
end
end
1 change: 0 additions & 1 deletion app/models/rails_xapi/activity_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def extensions=(extensions_data)
# If none, build and save the extension
if exts.blank? && extensions.blank?
extensions_data.each do |iri, data|
p data
extensions.build(iri: iri, value: serialized_value(data))
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/rails_xapi/actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def to_hash

def set_defaults
# We need to match the camel case notation from JSON data.
self.object_type = objectType.presence || "Agent"
self.object_type = objectType.presence || object_type.presence || OBJECT_TYPES.first
end

# Normalizes the actor data.
Expand Down
5 changes: 3 additions & 2 deletions app/models/rails_xapi/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def instructor=(value)

# Set the team value and create the actor if provided.
def team=(value)
actor_row = find_or_create_actor_with_account(value)
actor_row = find_or_create_actor_with_account(value, "Group")
self[:team_id] = actor_row.id if actor_row&.id.present?
end

Expand All @@ -61,7 +61,7 @@ def extensions=(extensions_data)

private

def find_or_create_actor_with_account(value)
def find_or_create_actor_with_account(value, object_type = nil)
home_page = value.dig(:account, :homePage)
existing_account = RailsXapi::Account.find_by(home_page: home_page) if home_page.present?

Expand All @@ -75,6 +75,7 @@ def find_or_create_actor_with_account(value)

RailsXapi::Actor.find_or_create_by(actor_params) do |actor|
actor.name = value[:name] if value[:name].present?
actor.object_type = object_type if object_type.present?
actor.account = RailsXapi::Account.new(value[:account]) if value[:account].present?
end
end
Expand Down
2 changes: 1 addition & 1 deletion config/locales/rails_xapi.en.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
en:
rails_xapi:
xapi_statement: "xAPI statement"
errors:
actor_ifi_must_be_present: "at least one of mbox, mbox_sha1sum, openid, or account must be present"
attribute_must_be_a_hash: "attribute %{name} must be a hash"
Expand Down Expand Up @@ -35,3 +34,4 @@ en:
min: "min must be a decimal number lower than max"
raw: "raw must be a decimal between min and max inclusive"
scaled: "scaled must be a decimal number between -1 and 1 inclusive"
xapi_statement: "xAPI statement"
185 changes: 184 additions & 1 deletion config/locales/rails_xapi.fr.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
fr:
rails_xapi:
xapi_statement: "déclaration xAPI"
errors:
actor_ifi_must_be_present: "au moins mbox, mbox_sha1sum, openid, ou account doit être présent"
attribute_must_be_a_hash: "l'attribut %{name} doit être un hash"
Expand Down Expand Up @@ -35,3 +34,187 @@ fr:
min: "min doit être un nombre décimal inférieur à max"
raw: "raw doit être un nombre décimal compris entre min et max inclus"
scaled: "scaled doit être un nombre décimal compris entre -1 and 1 inclus"
xapi_statement: "déclaration xAPI"
xapi:
activity: "activité"
actor: "acteur"
agent: "agent"
context: "contexte"
group: "groupe"
statement: "déclaration"
substatement: "sous-déclaration"
verb: "verbe"
verbs:
"accepted": "accepté"
"accessed": "accédé"
"acknowledged": "reconnu"
"added": "ajouté"
"agreed": "accepté"
"appended": "ajouté"
"approved": "approuvé"
"archived": "archivé"
"assigned": "assigné"
"was at": "était à"
"attached": "attaché"
"attended": "assisté"
"authored": "rédigé"
"authorized": "autorisé"
"borrowed": "emprunté"
"built": "construit"
"canceled": "annulé"
"checked in": "enregistré"
"closed": "fermé"
"completed": "complété"
"confirmed": "confirmé"
"consumed": "consommé"
"created": "créé"
"deleted": "supprimé"
"delivered": "livré"
"denied": "refusé"
"disagreed": "désaccordé"
"disliked": "pas aimé"
"experienced": "expérimenté"
"favorited": "mis en favori"
"found": "trouvé"
"flagged as inappropriate": "signalé comme inapproprié"
"followed": "suivi"
"gave": "donné"
"hosted": "organisé"
"ignored": "ignoré"
"inserted": "inséré"
"installed": "installé"
"interacted": "interagi"
"invited": "invité"
"joined": "rejoint"
"left": "quitté"
"liked": "aimé"
"listened": "écouté"
"lost": "perdu"
"made friend": "fait ami"
"opened": "ouvert"
"played": "joué"
"presented": "présenté"
"purchased": "acheté"
"qualified": "qualifié"
"read": "lu"
"received": "reçu"
"rejected": "rejeté"
"removed": "retiré"
"removed friend": "retiré ami"
"replaced": "remplacé"
"requested": "demandé"
"requested friend": "demandé en ami"
"resolved": "résolu"
"retracted": "rétracté"
"returned": "retourné"
"RSVPed maybe": "répondu peut-être"
"rsvped no": "répondu non"
"rsvped yes": "répondu oui"
"satisfied": "satisfait"
"saved": "enregistré"
"scheduled": "planifié"
"searched": "recherché"
"sold": "vendu"
"sent": "envoyé"
"shared": "partagé"
"sponsored": "sponsorisé"
"started": "commencé"
"stopped following": "arrêté de suivre"
"submitted": "soumis"
"tagged": "étiqueté"
"terminated": "terminé"
"tied": "lié"
"unfavorited": "retiré des favoris"
"unliked": "désaimé"
"unsatisfied": "insatisfait"
"unsaved": "non enregistré"
"unshared": "non partagé"
"updated": "mis à jour"
"used": "utilisé"
"watched": "regardé"
"won": "gagné"
"answered": "répondu"
"asked": "demandé"
"attempted": "tenté"
"commented": "commenté"
"exited": "sorti"
"failed": "échoué"
"imported": "importé"
"initialized": "initialisé"
"launched": "lancé"
"mastered": "maîtrisé"
"passed": "réussi"
"preferred": "préféré"
"progressed": "progressé"
"registered": "enregistré"
"responded": "répondu"
"resumed": "repris"
"scored": "noté"
"suspended": "suspendu"
"voided": "annulé"
"edited": "édité"
"voted down (with reason)": "voté contre (avec raison)"
"voted up (with reason)": "voté pour (avec raison)"
"pressed": "pressé"
"released": "relâché"
"adjourned": "ajourné"
"applauded": "applaudi"
"arranged": "organisé"
"bookmarked": "mis en favori"
"called": "appelé"
"closed sale": "vente conclue"
"created opportunity": "créé une opportunité"
"defined": "défini"
"disabled": "désactivé"
"discarded": "jeté"
"downloaded": "téléchargé"
"earned": "gagné"
"enabled": "activé"
"estimated the duration": "estimé la durée"
"expected": "attendu"
"expired": "expiré"
"focused": "concentré"
"entered frame": "entré dans le cadre"
"exited frame": "sorti du cadre"
"hired": "embauché"
"interviewed": "interviewé"
"laughed": "ri"
"unread": "non lu"
"mentioned": "mentionné"
"mentored": "mentoré"
"paused": "mis en pause"
"performed": "effectué"
"personalized": "personnalisé"
"previewed": "prévisualisé"
"promoted": "promu"
"rated": "évalué"
"replied": "répondu"
"replied to tweet": "a répondu au tweet"
"requested attention": "a demandé de l'attention"
"retweeted": "retweeté"
"reviewed": "révisé"
"secured": "sécurisé"
"selected": "sélectionné"
"skipped": "passé"
"talked": "parlé"
"terminated employment with": "terminé l'emploi avec"
"tweeted": "tweeté"
"unfocused": "détourné"
"unregistered": "désinscrit"
"viewed": "vu"
"down voted": "voté contre"
"up voted": "voté pour"
"was assigned job title": "a reçu le titre de poste"
"was hired by": "a été embauché par"
"annotated": "annoté"
"modified annotation": "annotation modifiée"
"earned an Open Badge": "gagné un Open Badge"
"drew": "dessiné"
"cancelled planned learning": "a annulé l'apprentissage planifié"
"planned": "planifié"
"enrolled onto learning plan": "inscrit au plan d'apprentissage"
"evaluated": "évalué"
"log in": "connecté"
"log out": "déconnecté"
"ran": "couru"
"walked": "marché"
6 changes: 6 additions & 0 deletions lib/rails-xapi/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ module RailsXapi
class Engine < ::Rails::Engine
isolate_namespace RailsXapi

initializer "local_helper.action_controller" do
ActiveSupport.on_load :action_controller do
helper RailsXapi::ApplicationHelper
end
end

config.before_configuration do
RailsXapi.configuration ||= RailsXapi::Configuration.new
end
Expand Down
34 changes: 34 additions & 0 deletions spec/helpers/rails_xapi/application_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# spec/helpers/rails_xapi/application_helper_spec.rb

require "rails_helper"

describe RailsXapi::ApplicationHelper, type: :helper do
it "should output the duration in minutes" do
result = RailsXapi::Result.new(
duration: "PT1H00M01.00S",
statement: RailsXapi::Statement.new(@default_statement)
)

expect(duration_to_minutes(result.duration)).to eq("60.02")
end
end

# == Schema Information
#
# Table name: rails_xapi_results
#
# id :integer not null, primary key
# completion :boolean default(FALSE)
# duration :string
# response :text
# score_max :integer
# score_min :integer
# score_raw :integer
# score_scaled :decimal(3, 2)
# success :boolean default(FALSE)
# statement_id :bigint not null
#
# Indexes
#
# index_rails_xapi_results_on_statement_id (statement_id)
#
2 changes: 1 addition & 1 deletion spec/models/rails_xapi/actor_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# spec/models/result_spec.rb
# spec/models/rails_xapi/result_spec.rb

require "rails_helper"

Expand Down
31 changes: 31 additions & 0 deletions spec/models/rails_xapi/context_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# spec/models/rails_xapi/context_spec.rb

require "rails_helper"

describe RailsXapi::Context do
include_context "statement"

before do
@actor = {
name: "Actor 1",
mbox_sha1sum: "sha1:d35132bd0bfc15ada6f5229002b5288d94a46f52",
openid: "http://example.com/object/Actor#1"
}

@statement = RailsXapi::Statement.new(@default_statement)
@statement.save!
end

it "should be create an instructor" do
context = RailsXapi::Context.new(instructor: @actor)

expect(context.instructor.class).to eq(RailsXapi::Actor)
end

it "should be create a team" do
context = RailsXapi::Context.new(team: @actor)

expect(context.team.class).to eq(RailsXapi::Actor)
expect(context.team.object_type).to eq("Group")
end
end
2 changes: 1 addition & 1 deletion spec/models/rails_xapi/object_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# spec/models/result_spec.rb
# spec/models/rails_xapi/object_spec.rb

require "rails_helper"

Expand Down
2 changes: 1 addition & 1 deletion spec/models/rails_xapi/result_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# spec/models/result_spec.rb
# spec/models/rails_xapi/result_spec.rb

require "rails_helper"

Expand Down
21 changes: 3 additions & 18 deletions spec/models/rails_xapi/statement_spec.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,22 @@
# spec/models/statement_spec.rb
# spec/models/rails_xapi/statement_spec.rb

require "rails_helper"

RSpec.describe RailsXapi::Statement, type: :model do
include_context "statement"

describe "validations" do
before :all do
RailsXapi::Statement.delete_all
RailsXapi::Actor.delete_all
RailsXapi::Verb.delete_all
RailsXapi::Object.delete_all

@verb = RailsXapi::Verb.new(id: RailsXapi::Verb::VERBS_LIST.keys[0])

@actor = RailsXapi::Actor.new(
name: "Actor 1",
mbox_sha1sum: "sha1:d35132bd0bfc15ada6f5229002b5288d94a46f52",
openid: "http://example.com/object/Actor#1"
)

@account = RailsXapi::Account.new(
name: "Actor#1",
homePage: "http://example.com/actor1"
)

@object = RailsXapi::Object.new(id: "/object/1")

# Create a statement with an Activity object (by default)
@default_statement = {
verb: @verb,
object: @object,
actor: @actor
}

# Create a statement with a SubStatement object
@substatement_statement = {
verb: @verb,
Expand Down
Loading

0 comments on commit c150304

Please sign in to comment.