Module: RailsXapi::ApplicationHelper
- Included in:
- ActivityDefinition
- Defined in:
- app/helpers/rails_xapi/application_helper.rb
Instance Method Summary collapse
-
#duration_to_minutes(duration) ⇒ Object
Output the duration ISO 8601 in minutes.
-
#json_value_for_locale(json_str, locale = I18n.locale) ⇒ Object
Output the value of a JSON row in a specific locale.
-
#result_success_rate(result) ⇒ Object
Output the result score as a percentage.
Instance Method Details
#duration_to_minutes(duration) ⇒ Object
Output the duration ISO 8601 in minutes.
6 7 8 |
# File 'app/helpers/rails_xapi/application_helper.rb', line 6 def duration_to_minutes(duration) sprintf("%.2f", ActiveSupport::Duration.parse(duration)&.in_minutes) end |
#json_value_for_locale(json_str, locale = I18n.locale) ⇒ Object
Output the value of a JSON row in a specific locale.
11 12 13 14 15 16 17 |
# File 'app/helpers/rails_xapi/application_helper.rb', line 11 def json_value_for_locale(json_str, locale = I18n.locale) hash = JSON.parse(json_str) result = hash.select { |key, _value| key.include?(locale.to_s) } result.values.first.to_s || hash.first.value.to_s rescue json_str end |
#result_success_rate(result) ⇒ Object
Output the result score as a percentage.
20 21 22 23 24 |
# File 'app/helpers/rails_xapi/application_helper.rb', line 20 def result_success_rate(result) return nil if result.score_raw.blank? || result.score_max.blank? ((result.score_raw.to_f / result.score_max.to_f) * 100).to_i end |