Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2026-04-04 03:19:03 UTC using RuboCop version 1.86.0.
# on 2026-04-15 09:29:09 UTC using RuboCop version 1.86.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation.
Bundler/OrderedGems:
Exclude:
- 'Gemfile'

# Offense count: 1
Gemspec/RequiredRubyVersion:
Exclude:
- 'unitsml.gemspec'

# Offense count: 75
# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: with_first_argument, with_fixed_indentation
Layout/ArgumentAlignment:
Exclude:
- 'lib/unitsml/unit.rb'

# Offense count: 76
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Max, AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, AllowRBSInlineAnnotation, AllowCopDirectives, AllowedPatterns, SplitStrings.
# URISchemes: http, https
Expand All @@ -40,6 +41,13 @@ Layout/LineLength:
- 'spec/unitsml/conv/xml_spec.rb'
- 'unitsml.gemspec'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowInHeredoc.
Layout/TrailingWhitespace:
Exclude:
- 'lib/unitsml/unit.rb'

# Offense count: 3
Lint/ReturnInVoidContext:
Exclude:
Expand Down Expand Up @@ -160,6 +168,12 @@ RSpec/SpecFilePathFormat:
- 'spec/unitsml/conv/unicode_spec.rb'
- 'spec/unitsml/conv/xml_spec.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/MultilineIfModifier:
Exclude:
- 'lib/unitsml/unit.rb'

# Offense count: 2
# Configuration parameters: AllowedMethods.
# AllowedMethods: respond_to_missing?
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ gemspec

gem "canon"
gem "lutaml-model", "~> 0.8.0", github: "lutaml/lutaml-model", branch: "main"
gem "mml"
gem "oga"
gem "ox"
gem "plurimath", github: "plurimath/plurimath", branch: "rt-lutaml-080"
Expand Down
4 changes: 4 additions & 0 deletions lib/unitsml/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,14 @@ def plurimath_available?
end

def nullify_mml_models
return unless defined?(Plurimath::Mathml::Parser::CONFIGURATION)

Plurimath::Mathml::Parser::CONFIGURATION.each_key { |klass| klass.model(klass) }
end

def reset_mml_models
return unless defined?(Plurimath::Mathml::Parser::CONFIGURATION)

::Mml::V4::Configuration.custom_models = Plurimath::Mathml::Parser::CONFIGURATION
end

Expand Down
21 changes: 17 additions & 4 deletions lib/unitsml/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ def unit_symbols
end

def to_mathml(options)
value = unit_symbols&.mathml
tag_name = value.match(/^<(?<tag>\w+)/)[:tag]
value = ::Mml::V4.const_get(tag_name.capitalize).from_xml(value)
value.value = "#{prefix.to_mathml(options)}#{value.value}" if prefix
raw_mathml = unit_symbols&.mathml
tag_name = raw_mathml.match(/^<(?<tag>\w+)/)[:tag]
klass = ::Mml::V4.const_get(tag_name.capitalize)
value = klass.from_xml(raw_mathml)
if prefix
value = with_updated_value(value,
"#{prefix.to_mathml(options)}#{value.value}")
end
if power_numerator
value = msup_tag(
{ method_name: tag_name, value: value },
Expand Down Expand Up @@ -126,6 +130,15 @@ def system_reference
unit_instance.unit_system_reference
end

def with_updated_value(element, new_value)
attrs = element.class.attributes.each_with_object({}) do |(name, _), h|
val = element.public_send(name)
h[name] = val unless val.nil?
end
attrs[:value] = new_value
element.class.new(**attrs)
end

def msup_tag(value, options)
msup = ::Mml::V4::Msup.new
msup.ordered = true
Expand Down
Loading
Loading