Class: Unitsml::Parse
- Inherits:
-
Parslet::Parser
- Object
- Parslet::Parser
- Unitsml::Parse
show all
- Includes:
- Unitsdb
- Defined in:
- lib/unitsml/parse.rb
Instance Method Summary
collapse
Methods included from Unitsdb
dimensions_hash, filtered_units, find_id, insert_vectors, load_dimensions, load_units, load_yaml, parsable_dimensions, prefixes, prefixes_hash, prefixs_ids, quantities, underscore, units, valid_path, vector
Instance Method Details
#arr_to_expression(arr, file_name) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/unitsml/parse.rb', line 57
def arr_to_expression(arr, file_name)
array = arr&.flatten&.compact&.sort_by(&:length).reverse
array&.reduce do |expression, expr_string|
expression = str(expression).as(file_name.to_sym) if expression.is_a?(String)
expression | str(expr_string).as(file_name.to_sym)
end
end
|
#extend_exp(rule) ⇒ Object
69
70
71
|
# File 'lib/unitsml/parse.rb', line 69
def extend_exp(rule)
(extender >> intermediate_exp(rule).as(:sequence)).maybe
end
|
73
74
75
|
# File 'lib/unitsml/parse.rb', line 73
def intermediate_exp(rule)
rule | (str("(") >> rule >> str(")"))
end
|
#sqrt(rule) ⇒ Object
65
66
67
|
# File 'lib/unitsml/parse.rb', line 65
def sqrt(rule)
str("sqrt(") >> rule.as(:sqrt) >> str(")")
end
|