engineer_calculator 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c03e6d4e5cc39e07d4dee7deed72a0d76004424f0ab48ebdb11ac7b5c50e023e
4
- data.tar.gz: 6af500776ffc9c40434d5ac3f25fe0f0ea0549be3dca8910c3e0478089fc66b1
3
+ metadata.gz: 32fe357799ad660cc4cfef2fad926400e8287afc853339b4e9d839f96562a811
4
+ data.tar.gz: 6e8289301ce855f7e754ac47312eb1d7e03b3cfe41883080a4b525a62847cb26
5
5
  SHA512:
6
- metadata.gz: 782e5beaafe3f3690d68f59a8731e2517c905fcbdafabd72c579bb987df044288749871c0fafe40a1bae35ab0859e1eb982a713dece37826b0e4613310acdbf0
7
- data.tar.gz: cfdf0997b87fba6a377167f3c30b7f5738c2c0db76e6f3194397ada055099f80da541913f54c03a70923126889b8555222b2d7b1e8f4bfb8c06b0d5cd7575d0e
6
+ metadata.gz: 26f9e977b09525668782a2e2479b90fccfc45b0e9e797220b7a445449a143c02e07db4ae2747980008fffe8e3f7de132ea4aee732ff57847e60deca666ff15d2
7
+ data.tar.gz: 6edaa70e71bb99122290b43c189857a2e92adcce8dea3f19298a79a31df94048cf266acdcced0e29df2ed7aa40de4f4d8ca01c766ead32c19a1b20ad0902f5c2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- engineer_calculator (1.0.1)
4
+ engineer_calculator (2.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -0,0 +1,61 @@
1
+ require "engineer_calculator/version"
2
+ require 'yaml'
3
+ require_relative "eng_unit"
4
+ require_relative "eng_unit_calc"
5
+ require_relative "eng_formula"
6
+
7
+ module Eng
8
+ class Calc
9
+ include Math
10
+ include Unit
11
+ include UnitCalc
12
+ include Formula
13
+
14
+ attr_accessor :error, :alter
15
+ def calc(formula)
16
+
17
+ return nil unless formula
18
+
19
+ begin
20
+ c = { value: "", unit: [], si_formula: "", error: [] }
21
+
22
+ split_value_unit(formula.gsub("⋅","*")).map do |e_formula|
23
+ if e_formula[:unit].nil?
24
+ c[:value] << e_formula[:value].to_f.to_s + "r"
25
+ c[:si_formula] << e_formula[:value]
26
+ elsif e_formula[:value] =~ /#{operator_reg(:ari)}/
27
+ c[:value] << e_formula[:value]
28
+ c[:unit] << e_formula[:value]
29
+ c[:si_formula] << " " + e_formula[:value] + " "
30
+ else
31
+ result = convert(e_formula)
32
+ result[:value].to_f
33
+ c[:value] << result[:value].to_f.rationalize.to_s + "r"
34
+ c[:unit] << result[:unit].unshift("(").push(")")
35
+ c[:error] << result[:error] unless result[:error].nil? || result[:error].empty?
36
+ c[:si_formula] << result[:value].to_s + " " + result[:unit].join
37
+ end
38
+ end
39
+ c_unit = calc_unit(c[:unit].flatten)
40
+ { value: eval(c[:value]).to_f,
41
+ unit: c_unit[:unit],
42
+ error: (c[:error] << c_unit[:error]).flatten.compact,
43
+ si_formula: c[:si_formula] }
44
+
45
+ rescue StandardError, SyntaxError
46
+ { value: "error", unit: "", error: "undifined formula", si_formula: formula}
47
+ end
48
+ end
49
+
50
+ def each_value(value: , si_unit: nil, kind: nil)
51
+ value = value.to_f.rationalize
52
+ kind = Unit.kind_by_si(si_unit) if si_unit
53
+ return false unless kind || Unit.variable[kind]
54
+ results = Unit.variable[kind].map do |unit|
55
+ { unit: unit[0],
56
+ value: eval(liner_function(unit[1])).to_f }
57
+ end
58
+ { kind: kind, result: results }
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,128 @@
1
+ module Eng
2
+ module Formula
3
+ def split_value_unit(formula)
4
+ unit_array = []
5
+ formula_pre = formula.to_s.delete(" ")
6
+ formula_pre.scan(/(#{operator_reg(:tri)})|
7
+ (?:(#{operator_reg(:num)}(?:#{operator_reg(:double)})*)((?:\/?\(?\/?[a-z]+\d*(?:\*[a-z])*(?:\W*[a-z]\d*\)*)*)(?:\d[^[a-z]])*\)?))|
8
+ (#{operator_reg(:ari)})|
9
+ ((?:#{operator_reg(:num)})*(?:#{operator_reg(:double)})?)/ix)
10
+ .each do |data|
11
+ unit_array << {
12
+ value: (data[0] || data[1] || data[3] || data[4]),
13
+ unit: (data[2] || data[3]) }
14
+ end
15
+
16
+ unit_array.each_with_index do |data, index|
17
+ if data[:unit] =~ /^[^\(]+\)$/
18
+ data[:unit].gsub!(/.$/,'')
19
+ unit_array.insert(index+1, { value: ")", unit: ")" })
20
+ end
21
+ end
22
+ unit_array.delete_if{ |data| true if data[:value].empty? && data[:unit].nil? }
23
+ end
24
+
25
+ def operator_reg(kind_operator)
26
+ case kind_operator
27
+ when :ari
28
+ /(?:[\(\)\+\-\*\/])/
29
+ when :double #2乗表現のマッチング (2^1/2)
30
+ /(?:\^\(?[\+\-]?\d+\/?\d*\)?)/
31
+ when :num
32
+ /\d+(?:\.\d*)?(?:e[+-]?\d+)?/
33
+ when :tri
34
+ /(?:sin|cos|tan)\(.+\)/
35
+ end
36
+ end
37
+
38
+ def split_by_ari(formula)
39
+ formula.split((/(#{operator_reg(:ari)})/))
40
+ end
41
+
42
+ def liner_function(formula)
43
+ formula_arr = formula.split(/(\*|\/|\+|-)/)
44
+ input_num = formula_arr.index("value")
45
+ mv_num = formula_arr.index{ |n| n =~ /\*|\// }
46
+ pm_num = formula_arr.index{ |n| n =~ /\+|-/ }
47
+
48
+ if mv_num
49
+ a_ari = formula_arr[mv_num]
50
+ if input_num > mv_num
51
+ a = formula_arr[mv_num - 1]
52
+ else
53
+ a = formula_arr[mv_num + 1]
54
+ end
55
+ else
56
+ a_ari = "/"
57
+ a = 1
58
+ end
59
+
60
+ if pm_num
61
+ b_ari = formula_arr[pm_num]
62
+ if input_num > pm_num
63
+ b = formula_arr[pm_num - 1]
64
+ else
65
+ b = formula_arr[pm_num + 1]
66
+ end
67
+ else
68
+ b_ari = "+"
69
+ b = 0
70
+ end
71
+
72
+ a_ari == "*" ? a_ari = "/" : a_ari = "*"
73
+ b_ari == "+" ? b_ari = "-" : b_ari = "+"
74
+
75
+ "value" + a_ari + a.to_s + b_ari + b.to_s + a_ari + a.to_s
76
+ end
77
+
78
+ def new_liner_function(formula)
79
+ fl_arr = formula.split(/(\*|\/|\+|-)/)
80
+ value_i = fl_arr.index("value")
81
+
82
+ a = []
83
+ b = []
84
+ pl = false
85
+ (value_i .. fl_arr.size - 1).each do |i|
86
+ if pl || fl_arr[i] == "+" || fl_arr[i] == "-"
87
+ b << reverse_operator(fl_arr[i])
88
+ pl = true
89
+ else
90
+ a << reverse_operator(fl_arr[i])
91
+ end
92
+ end
93
+
94
+ if value_i != 0
95
+ (0 .. value_i - 1).reverse_each do |i|
96
+ if fl_arr[i] == "+" || fl_arr[i] == "-" || i == 0
97
+ (i .. value_i - 1).reverse_each do |ii|
98
+ a.unshift(reverse_operator(fl_arr[ii]))
99
+ end
100
+
101
+ if i != 0
102
+ (0..i).each do |ii|
103
+ b.unshift(reverse_operator(fl_arr[ii], false))
104
+ end
105
+ end
106
+ break
107
+ end
108
+ end
109
+ end
110
+ a.join + "+(" + b.join + ")/value"
111
+ end
112
+
113
+ def reverse_operator(operator, opt = true)
114
+ case operator
115
+ when "+"
116
+ "-"
117
+ when "-"
118
+ "+"
119
+ when "*"
120
+ opt ? "/" : "*"
121
+ when "/"
122
+ opt ? "*" : "/"
123
+ else
124
+ operator
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,196 @@
1
+ require 'yaml'
2
+ require_relative 'eng_formula'
3
+ require_relative 'eng_unit_calc'
4
+
5
+ module Eng
6
+ module ExtensionClass
7
+ include Eng
8
+ refine Hash do
9
+ def to_names
10
+ case self
11
+ when Unit.variable
12
+ self.inject([]) do |a, k|
13
+ a << k[1].keys.inject([]) { |arr, key| arr << key.split(", ") }.flatten
14
+ end.flatten
15
+ when Unit.si_alter
16
+ self.inject([]) { |a, v| a << v }.flatten
17
+ when Unit.metric_prefix
18
+ self.keys
19
+ when Unit.si_base
20
+ self.values
21
+ end
22
+ end
23
+
24
+ def to_find(unit_name)
25
+ case self
26
+ when Unit.si_base, Unit.si_derived
27
+ return {formula: "value", kind: self.key(unit_name)} if self.key(unit_name)
28
+ when Unit.si_alter
29
+ self.each do |kind, units|
30
+ return {formula: "value", kind: kind} if units.include?(unit_name)
31
+ end
32
+ when Unit.variable
33
+ self.each do |kind_unit|
34
+ kind_unit[1].each do |unit, value|
35
+ return {formula: value, kind: kind_unit[0]} if unit.split(", ").include?(unit_name)
36
+ end
37
+ end
38
+ end
39
+ nil
40
+ end
41
+
42
+ def to_reg
43
+ Regexp.new(self.to_names.sort{ |a,b| b.size <=> a.size }.map{|x| Regexp.escape(x)}.join("|"))
44
+ end
45
+ end
46
+
47
+ refine Object do
48
+ def send(name, *args)
49
+ return self unless name
50
+ super
51
+ end
52
+ end
53
+ end
54
+
55
+ module Unit
56
+ include Formula
57
+ attr_accessor :opt
58
+
59
+ def convert(value: , unit: )
60
+ values = nil
61
+ first_unit = false
62
+ convert_unit = split_by_ari(unit).map do |e_unit|
63
+ if e_unit.empty?
64
+ elsif e_unit =~ /(#{operator_reg(:ari)})/
65
+ values = e_unit
66
+ if e_unit == "/" && !first_unit
67
+ values = value.to_s + "/"
68
+ first_unit = true
69
+ end
70
+ { value: values, unit: e_unit }
71
+ else
72
+ values = first_unit ? 1 : value
73
+ first_unit = true
74
+ Unit.convert_to_si(value: values.to_f.rationalize, unit: e_unit)
75
+ end
76
+ end
77
+ results = convert_unit.compact.inject({ value: "", unit: [], error: [] }) do |result, convert|
78
+ result[:value] << convert[:value].to_s
79
+ result[:unit] << split_by_ari(convert[:unit]) if convert[:unit]
80
+ result[:error] << convert[:error] if convert[:error]
81
+ result
82
+ end
83
+ results[:value] = eval(results[:value] << "")
84
+ results[:unit].flatten!.reject!(&:empty?)
85
+ results
86
+ end
87
+
88
+ class << self
89
+ include Formula
90
+ include UnitCalc
91
+ using ExtensionClass
92
+ def si_base
93
+ @si_base_unit ||= YAML.load_file(File.join(__dir__, 'unit_calc/si_base_unit.yml'))
94
+ return @si_base_unit.inject({}){ |h, (k,v)| h[k] = v.upcase; h } if @opt
95
+ @si_base_unit
96
+ end
97
+
98
+ def si_derived
99
+ @si_derived_unit ||= YAML.load_file(File.join(__dir__, 'unit_calc/si_derived_unit.yml'))
100
+ return @si_derived_unit.inject({}){ |h, (k,v)| h[k] = v.upcase; h } if @opt
101
+ @si_derived_unit
102
+ end
103
+
104
+ def variable
105
+ @variable_unit ||= YAML.load_file(File.join(__dir__, 'unit_calc/variable_unit.yml'))
106
+ return @variable_unit.inject({}){ |h, (k,v)| h[k] = v.inject({}){ |hh, (kk, vv)| hh[kk.upcase] = vv; hh }; h } if @opt
107
+ @variable_unit
108
+ end
109
+
110
+ def metric_prefix
111
+ @metric_prefix ||= YAML.load_file(File.join(__dir__, 'unit_calc/metric_prefix.yml'))
112
+ return @metric_prefix.inject({}){ |h, (k,v)| h[k.upcase] = v; h } if @opt
113
+ @metric_prefix
114
+ end
115
+
116
+ def si_alter
117
+ @si_alter_unit ||= YAML.load_file(File.join(__dir__, 'unit_calc/si_alter_unit.yml'))
118
+ return @si_alter_unit.inject({}){ |h, (k,v)| h[k] = v.inject([]){ |a, aa| a << aa.upcase; a }; h } if @opt
119
+ @si_alter_unit
120
+ end
121
+
122
+ def find_all(unit)
123
+ [:si_base, :si_alter, :si_derived, :variable].each do |method|
124
+ result = Unit.send(method).to_find(unit)
125
+ return result if result
126
+ end
127
+ nil
128
+ end
129
+
130
+ def convert_to_si(value: , unit: , opt: nil)
131
+ value = value.rationalize
132
+ metric = nil
133
+ num = 1
134
+ @opt = opt
135
+ original_unit = unit
136
+ unit = unit.send(opt)
137
+ if unit.match(to_si_reg) do |si_unit|
138
+ break if si_unit[0] != unit || si_unit[0].upcase == "KG"
139
+ metric = si_unit[:metric]
140
+ unit = si_unit[:si] + (si_unit[:num] || "")
141
+ num = si_unit[:num] || 1
142
+ end
143
+ end
144
+
145
+ result = find_all(unit)
146
+
147
+ if !result && !opt
148
+ convert_to_si(value: value, unit: unit, opt: :upcase)
149
+ elsif result
150
+ @opt = nil
151
+ metric = metric ? (metric_prefix[original_unit[0]].to_f ** num.to_f).rationalize : 1
152
+ {
153
+ value: eval(result[:formula].to_s + "*#{metric}").to_f,
154
+ unit: to_si(result[:kind]),
155
+ kind: result[:kind],
156
+ error: opt ? { unit_upcase: original_unit } : nil
157
+ }
158
+ else
159
+ {
160
+ value: value,
161
+ unit: original_unit,
162
+ kind: nil,
163
+ error: original_unit.empty? ? nil : { unit_not_found: original_unit }
164
+ }
165
+ end
166
+ end
167
+
168
+ def kind_by_si(unit)
169
+ s_unit = unit_arrange(split_by_ari(unit))
170
+ si_base.merge(si_derived).each do |e_unit|
171
+ return e_unit[0] if s_unit == unit_arrange(split_by_ari(e_unit[1]))
172
+ end
173
+ false
174
+ end
175
+
176
+ def to_si(kind_unit)
177
+ si_base[kind_unit] || si_derived[kind_unit]
178
+ end
179
+
180
+ def to_si_reg
181
+ /((?<metric>#{metric_prefix.to_reg})(?<si>#{si_base.to_reg}|g){1}(?<num>-*\d)*)|((?<metric>#{metric_prefix.to_reg})(?<si>#{si_alter.to_reg}))/
182
+ end
183
+
184
+ def unit_reg
185
+ /(#{si_derived.to_reg})|((?:#{metric_prefix.to_reg})?#{si_alter.to_reg})|(#{variable.to_reg})|((?:#{metric_prefix.to_reg})?(?:#{si_base.to_reg}|g){1}-*\d*)|(#{operator_reg(:ari)})/
186
+ end
187
+
188
+ def variable_names
189
+ variable.inject({}) do |a, k|
190
+ a[k[0]] = k[1].keys.join(", ").split(", ")
191
+ a
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
@@ -0,0 +1,128 @@
1
+ require_relative "eng_formula"
2
+
3
+ module Eng
4
+ module UnitCalc
5
+ include Formula
6
+ def calc_unit(units)
7
+ @error = {}
8
+ units = split_by_ari(units) unless units.class == Array
9
+ par = parenthesis_unit(units)
10
+ par.reverse_each do |index|
11
+ by_value = units[index[0]..index[1]]
12
+ unit = plus_minus_split(by_value)
13
+ unit.map! do |each_unit|
14
+ multi_div_unit each_unit
15
+ end
16
+ unit = plus_minus_unit(unit)
17
+ add = by_value.include?("(") ? 1 : 0
18
+ units[(index[0]+add)..(index[1]-add)] = unit + Array.new(units[(index[0]+add)..(index[1]-add)].size-unit.size)
19
+ end
20
+ units.compact!
21
+ units.reject!{ |x| x =~ /\(|\)/ }
22
+ { unit: unit_arrange(units), error: @error }
23
+ end
24
+
25
+ def plus_minus_unit(array)
26
+ array.each_with_index do |value, i|
27
+ unless i == 0 || (array[i-1].sort == array[i].sort)
28
+ @error[:plus_minus] ||= []
29
+ @error[:plus_minus] << "#{unit_arrange(array[i-1])} + #{unit_arrange(array[i])}"
30
+ end
31
+ end
32
+ array[0]
33
+ end
34
+
35
+ def plus_minus_split(units)
36
+ if units.any?{|x| x=="+" || x=="-"}
37
+ num = [0]
38
+ array = []
39
+ units.each_with_index { |x, i| num << i if x == "+" || x == "-" }
40
+ num << units.size - 1
41
+ num.each_with_index { |x, i| array << units[num[i-1]..x].reject!{|x| ["+", "-"].include?(x) } unless i==0 }
42
+ array
43
+ else
44
+ [units]
45
+ end
46
+ end
47
+
48
+ def multi_div_unit(units)
49
+ unit_hash = Hash.new(0)
50
+ ari = "+"
51
+ end_par = "+"
52
+ units.compact! unless units.nil?
53
+ units.each do |unit|
54
+ case unit
55
+ when "*", "・", "⋅"
56
+ ari = "+" unless end_par == "-"
57
+ when "/"
58
+ ari = "-"
59
+ when "("
60
+ end_par = "-" if ari == "-"
61
+ when ")"
62
+ end_par = "+"
63
+ else
64
+ num = unit.match(/(?<base>\D+){1}(?<num>-*\d*)/)
65
+ base = num[:base]
66
+ num = num[:num].empty? ? 1 : num[:num]
67
+ unit_hash[base] = eval(unit_hash[base].to_s + ari + num.to_s)
68
+ ari = "+" unless end_par == "-"
69
+ end
70
+ end
71
+ unit_hash.sort{|a,b| b[1] <=> a[1]}.map { |key, value| value == 0 ? nil : key + value.to_s }.compact
72
+ end
73
+
74
+ def parenthesis_unit(formula) #formula = ["(", "m","/","s", ")"]
75
+ array = []
76
+ count = []
77
+ formula.each_with_index do |value, index|
78
+ case value
79
+ when "("
80
+ array.push [index, nil]
81
+ count << array.size - 1
82
+ when ")"
83
+ array[count.pop][1] = index
84
+ end
85
+ end
86
+ array.unshift([0,formula.size-1])
87
+ end
88
+
89
+ def unit_arrange(units)
90
+ pos = []
91
+ neg = []
92
+ units.each do |unit|
93
+ num = unit.match(/(?<base>(?:[a-zA-Z]+))(?<num>-*\d*)/)
94
+ unless num.nil?
95
+ if num[:num].nil? || num[:num].to_i.positive?
96
+ number = num[:num].to_i == 1 ? nil : num[:num]
97
+ pos << num[:base] + number.to_s
98
+ else
99
+ number = num[:num].to_i == -1 ? nil : - (num[:num].to_i)
100
+ neg << num[:base] + number.to_s
101
+ end
102
+ end
103
+ end
104
+ div = neg.size > 1 ? ("/" + "(" + neg.join("*") + ")") : (neg.empty? ? nil : "/" + neg.join.to_s)
105
+ pos.join("*") + div.to_s
106
+ end
107
+
108
+ def split_si_unit(si_unit)
109
+ unit = si_unit.split(/([\*\/\(\)])/).reject(&:empty?).map do |s_unit|
110
+ s_unit =~ /([\*\/\(\)])/ ? s_unit : extraction_metric(s_unit)
111
+ end
112
+ value = String.new
113
+ unit_si = []
114
+ unit.each do |each_unit|
115
+ case each_unit
116
+ when Array
117
+ value << each_unit[0].to_s
118
+ unit_si << each_unit[1]
119
+ when String
120
+ value << each_unit.to_s
121
+ unit_si << each_unit
122
+ end
123
+ end
124
+ [eval(value.gsub(/^(#{operator_reg(:ari)})/,"")), unit_si]
125
+ end
126
+
127
+ end
128
+ end
@@ -34,6 +34,7 @@ module Engineer
34
34
  value << x[0].to_s.sub("^","**") + (x[0].to_s =~ Regexp.union(reg(:ari),/(?:#{reg(:num)})*(?:#{reg(:double)})+/) ? "" : ".rationalize") unless x[0].empty?
35
35
  units << x[1]
36
36
  end
37
+ p units
37
38
  @opt = nil
38
39
  converted_formula = formula.inject(String.new){ |f, v| f << v[0].to_s + (v[0] != v[1].join ? v[1].join : " ") }
39
40
  return @result = { value: eval(value).to_f, unit: units.flatten.join, convert_formula: converted_formula } unless @error[:unit_not_found].nil?
@@ -274,21 +275,6 @@ module Engineer
274
275
  end
275
276
  end
276
277
 
277
- def split_test(formula)
278
- unit_array = []
279
- formula_pre = formula.to_s.delete(" ")
280
- formula_pre.scan(/(#{reg(:tri)})|(?:(#{reg(:num)}(?:#{reg(:double)})*)((?:\/?\(?\/?[a-z]+\d*(?:\*[a-z])*(?:\W*[a-z]\d*\)*)*)(?:-*\d[^[a-z]])*\)?))|(#{reg(:ari)})|((?:#{reg(:num)})*(?:#{reg(:double)})?)/i).each do |data|
281
- unit_array << { value: (data[0] || data[1] || data[3] || data[4]), unit: (data[2] || data[3]) }
282
- end
283
- unit_array.each_with_index do |data, index|
284
- if data[:unit] =~ /^[^\(].+\)$/
285
- data[:unit].gsub!(/.$/,'')
286
- unit_array.insert(index+1, { value: ")", unit: ")" })
287
- end
288
- end
289
- unit_array
290
- end
291
-
292
278
  def split_unit(formula)
293
279
  unit_array = []
294
280
  formula_pre = formula.to_s.delete(" ")
@@ -1,3 +1,3 @@
1
1
  module Engineer
2
- VERSION = "1.1.0"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -89,22 +89,10 @@ Radiant Intensity:
89
89
  Spectral Intensity:
90
90
  - W/(sr*m)
91
91
  - watt per steradian metre
92
- Speed, Velocity:
93
- - m/s
94
- Acceleration:
95
- - m/s2
96
- Jerk, Jolt:
97
- - m/s3
98
- Snap, Jounce:
99
- - m/s4
100
92
  Angular Velocity:
101
93
  - rad/s
102
94
  Angular Acceleration:
103
95
  - rad/s2
104
- Frequency Drift:
105
- - /s2
106
- Volumetric Flow:
107
- - m3/s
108
96
  Frequency:
109
97
  - Hz
110
98
  - hertz
@@ -155,7 +143,6 @@ Electrical Capacitance:
155
143
  Electrical Resistance, Impedance, Reactance:
156
144
  - Ω
157
145
  - ohm
158
- - /S
159
146
  - V/A
160
147
  Electrical Conductance:
161
148
  - S
@@ -196,7 +183,6 @@ Illuminance:
196
183
  Radioactivity (Decays Per Unit Time):
197
184
  - Bq
198
185
  - becquerel
199
- - /s
200
186
  Absorbed Dose (Of Ionizing Radiation):
201
187
  - Gy
202
188
  - gray
@@ -208,4 +194,3 @@ Equivalent Dose (Of Ionizing Radiation):
208
194
  Catalytic Activity:
209
195
  - kat
210
196
  - katal
211
- - mol/s
@@ -0,0 +1,10 @@
1
+ Tempreture:
2
+ K: input
3
+ °C, degree, Celsius: input-273.15r
4
+ °F, Fahrenheit: input*1.8r-459.67r
5
+ °R, Rankine scale: input*1.8r
6
+
7
+ Length:
8
+ m: input
9
+ inch, in, ": input*39.370078740158
10
+ feet, ft, ': input*3.2808398950131
@@ -0,0 +1,20 @@
1
+ Y: 10e23
2
+ Z: 10e20
3
+ E: 10e17
4
+ P: 10e14
5
+ T: 10e11
6
+ G: 10e8
7
+ M: 10e5
8
+ k: 10e2
9
+ h: 10e1
10
+ da: 1
11
+ d: 10e-2
12
+ c: 10e-3
13
+ m: 10e-4
14
+ μ: 10e-7
15
+ n: 10e-10
16
+ p: 10e-13
17
+ f: 10e-16
18
+ a: 10e-19
19
+ z: 10e-22
20
+ y: 10e-25
@@ -0,0 +1,211 @@
1
+ Area:
2
+ - square metre
3
+ Volume:
4
+ - cubic metre
5
+ Momentum, Impulse:
6
+ - N*s
7
+ - Ns
8
+ - newton second
9
+ Angular Momentum:
10
+ - newton metre second
11
+ - N*m*s
12
+ - Nms
13
+ Torque, moment of force:
14
+ - newton metre
15
+ - N*m
16
+ - J/rad
17
+ Yank:
18
+ - newton per second
19
+ - N/s
20
+ Wavenumber, Optical Power, Curvature, Spatial Frequency:
21
+ - reciprocal metre
22
+ Area Density:
23
+ - kilogram per square metre
24
+ Density, Mass density:
25
+ - kilogram per cubic metre
26
+ Specific Volume:
27
+ - cubic metre per kilogram
28
+ Action:
29
+ - J*s
30
+ - joule second
31
+ Specific Energy:
32
+ - J/kg
33
+ - joule per kilogram
34
+ Energy Density:
35
+ - J/m3
36
+ - joule per cubic metre
37
+ Surface Tension, Stiffness:
38
+ - N/m
39
+ - J/m2
40
+ - newton per metre
41
+ Heat Flux Density, Irradiance:
42
+ - W/m2
43
+ - watt per square metre
44
+ Kinematic Viscosity, Thermal Diffusivity, Diffusion Coefficient:
45
+ - square metre per second
46
+ Dynamic Viscosity:
47
+ - Pa*s
48
+ - N*s/m2
49
+ - pascal second
50
+ linear Mass Density:
51
+ - kilogram per metre
52
+ Mass Flow Rate:
53
+ - kilogram per second
54
+ Radiance:
55
+ - W/(sr*m2)
56
+ - watt per steradian square metre
57
+ Spectral Radiance:
58
+ - W/(sr*m3)
59
+ - watt per steradian cubic metre
60
+ Spectral Power:
61
+ - W/m
62
+ - watt per metre
63
+ Absorbed Dose Rate:
64
+ - Gy/s
65
+ - gray per second
66
+ Fuel Efficiency:
67
+ - m/m3
68
+ - metre per cubic metre
69
+ Spectral Irradiance, Power Density:
70
+ - W/m3
71
+ - watt per cubic metre
72
+ Energy Flux Density:
73
+ - J/(m2⋅s)
74
+ - joule per square metre second
75
+ Compressibility:
76
+ - /Pa
77
+ - reciprocal pascal
78
+ Radiant Exposure:
79
+ - J/m2
80
+ - joule per square metre
81
+ Moment of Inertia:
82
+ - kilogram square metre
83
+ Specific Angular Momentum:
84
+ - N*m*s/kg
85
+ - newton metre second per kilogram
86
+ Radiant Intensity:
87
+ - W/sr
88
+ - watt per steradian
89
+ Spectral Intensity:
90
+ - W/(sr*m)
91
+ - watt per steradian metre
92
+ Speed, Velocity:
93
+ - m/s
94
+ Acceleration:
95
+ - m/s2
96
+ Jerk, Jolt:
97
+ - m/s3
98
+ Snap, Jounce:
99
+ - m/s4
100
+ Angular Velocity:
101
+ - rad/s
102
+ Angular Acceleration:
103
+ - rad/s2
104
+ Frequency Drift:
105
+ - /s2
106
+ Volumetric Flow:
107
+ - m3/s
108
+ Frequency:
109
+ - Hz
110
+ - hertz
111
+ Angle:
112
+ - rad
113
+ - radian
114
+ Solid Angle:
115
+ - sr
116
+ - steradian
117
+ Force, Weight:
118
+ - N
119
+ - newton
120
+ Pressure, Stress:
121
+ - Pa
122
+ - pascal
123
+ Energy, Work, Heat:
124
+ - J
125
+ - joule
126
+ - N*m
127
+ - Nm
128
+ - C*V
129
+ - CV
130
+ - W*s
131
+ - Ws
132
+ Power, Radiant Flux:
133
+ - W
134
+ - watt
135
+ - J/s
136
+ - V*A
137
+ - VA
138
+ Electric Charge Or Quantity Of Electricity:
139
+ - C
140
+ - coulomb
141
+ - s*A
142
+ - sA
143
+ - V*A
144
+ - VA
145
+ Voltage, Electrical Potential Difference, Electromotive Force:
146
+ - V
147
+ - volt
148
+ - W/A
149
+ - J/C
150
+ Electrical Capacitance:
151
+ - F
152
+ - farad
153
+ - C/V
154
+ - s/Ω
155
+ Electrical Resistance, Impedance, Reactance:
156
+ - Ω
157
+ - ohm
158
+ - /S
159
+ - V/A
160
+ Electrical Conductance:
161
+ - S
162
+ - siemens
163
+ - /Ω
164
+ - A/V
165
+ Magnetic Flux:
166
+ - Wb
167
+ - weber
168
+ - J/A
169
+ - T*m2
170
+ - Tm2
171
+ Magnetic Field Strength, Magnetic Flux Density:
172
+ - T
173
+ - tesla
174
+ - V*s/m2
175
+ - Vs/m2
176
+ - Wb/m2
177
+ - N/(A*m)
178
+ - N/(Am)
179
+ Electrical Inductance:
180
+ - H
181
+ - henry
182
+ - V*s/A
183
+ - Vs/A
184
+ - Ω*s
185
+ - Ωs
186
+ - Wb/A
187
+ Luminous Flux:
188
+ - lm
189
+ - lumen
190
+ - cd*sr
191
+ - cdsr
192
+ Illuminance:
193
+ - lx
194
+ - lux
195
+ - lm/m2
196
+ Radioactivity (Decays Per Unit Time):
197
+ - Bq
198
+ - becquerel
199
+ - /s
200
+ Absorbed Dose (Of Ionizing Radiation):
201
+ - Gy
202
+ - gray
203
+ - J/kg
204
+ Equivalent Dose (Of Ionizing Radiation):
205
+ - Sv
206
+ - sievert
207
+ - J/kg
208
+ Catalytic Activity:
209
+ - kat
210
+ - katal
211
+ - mol/s
@@ -0,0 +1,7 @@
1
+ Length: m
2
+ Weight: kg
3
+ Time: s
4
+ Current: A
5
+ Tempreture: K
6
+ Amaount of Substance: mol
7
+ Luminous intensity: cd
@@ -0,0 +1,62 @@
1
+ Area: m2
2
+ Volume: m3
3
+ Momentum, Impulse: m*kg/s
4
+ Angular Momentum: m2*kg/s
5
+ Torque, moment of force: m2*kg/s2
6
+ Yank: m*kg/s3
7
+ Wavenumber, Optical Power, Curvature, Spatial Frequency: /m
8
+ Area Density: kg/m2
9
+ Density, Mass density: kg/m3
10
+ Specific Volume: m3/kg
11
+ Action: m2*kg/s
12
+ Specific Energy: m2/s2
13
+ Energy Density: kg/(m*s2)
14
+ Surface Tension, Stiffness: kg/s2
15
+ Heat Flux Density, Irradiance: kg/s3
16
+ Kinematic Viscosity, Thermal Diffusivity, Diffusion Coefficient: m2/s
17
+ Dynamic Viscosity: kg/(m*s)
18
+ linear Mass Density: kg/m
19
+ Mass Flow Rate: kg/s
20
+ Radiance: kg/s3
21
+ Spectral Radiance: kg/(m*s3)
22
+ Spectral Power: m*kg/s3
23
+ Absorbed Dose Rate: m/s3
24
+ Fuel Efficiency: /m2
25
+ Spectral Irradiance, Power Density: kg/(m*s3)
26
+ Energy Flux Density: kg/s3
27
+ Compressibility: m*s2/kg
28
+ Radiant Exposure: kg/s2
29
+ Moment of Inertia: kg*m2
30
+ Specific Angular Momentum: m2/s
31
+ Radiant Intensity: m2*kg/s3
32
+ Spectral Intensity: m*kg/s3
33
+ Speed, Velocity: m/s
34
+ Acceleration: m/s2
35
+ Jerk, Jolt: m/s3
36
+ Snap, Jounce: m/s4
37
+ Angular Velocity: /s
38
+ Angular Acceleration: /s2
39
+ Frequency Drift: /s2
40
+ Volumetric Flow: m3/s
41
+ Frequency: /s
42
+ Angle: m/m
43
+ Solid Angle: m2/m2
44
+ Force, Weight: kg*m/s2
45
+ Pressure, Stress: kg/(m*s2)
46
+ Energy, Work, Heat: kg*m2/s2
47
+ Power, Radiant Flux: kg*m2/s3
48
+ Electric Charge Or Quantity Of Electricity: s*A
49
+ Voltage, Electrical Potential Difference, Electromotive Force: kg*m2/(s3*A)
50
+ Electrical Capacitance: s4A2/(kg*m2)
51
+ Electrical Resistance, Impedance, Reactance: kg*m2/(s3*A2)
52
+ Electrical Conductance: s3*A2/(kg*m2)
53
+ Magnetic Flux: kg*m2/(s2*A)
54
+ Magnetic Field Strength, Magnetic Flux Density: kg/(s2*A)
55
+ Electrical Inductance: kg*m2/(s2*A2)
56
+ Temperature: K
57
+ Luminous Flux: cd
58
+ Illuminance: cd/m2
59
+ Radioactivity (Decays Per Unit Time): /s
60
+ Absorbed Dose (Of Ionizing Radiation): m2/s2
61
+ Equivalent Dose (Of Ionizing Radiation): m2/s2
62
+ Catalytic Activity: mol/s
@@ -0,0 +1,174 @@
1
+ Length:
2
+ Å: value/10000000000r
3
+ thou, mil, milli-inch: value*0.0000254r
4
+ inch, in, ": value*0.0254r
5
+ feet, ft, ': value*0.304r
6
+ yard, yd: value*0.9144r
7
+ mile, mi: value*1609.344r
8
+ 寸: value*1/33
9
+ 尺: value*0.30303r
10
+ 鯨尺: value*0.37879r
11
+ 丈: value*3.0303r
12
+ 間: value*1.818r
13
+ 町, 丁: value*109.09091r
14
+ 里: value*3927.273r
15
+ 天文単位, astronomical-unit, AU: value*149597870700r
16
+ 光年, light-year, ly: value*9460730472580800r
17
+ パーセク, parsec, pc: value*3.085677581e16.rationalize
18
+ 海里, nautical-mile: value*1852r
19
+
20
+ Weight:
21
+ g, gram: value*1000r
22
+ ton: value*0.001r
23
+ grain, gr: value/15432.358352941r
24
+ dram, dr: value/564.38339119329r
25
+ ounce, oz: value/35.27396194958r
26
+ pound, lb: value/2.2046226218488r
27
+ stone, st: value*6.35029318r
28
+ quarter: value*12.70058636r
29
+ short-ton, sh-tn, s.t.: value*907.18474r
30
+ 分: value/2666.6666666667r
31
+ 匁: value/266.66666666667r
32
+ 百目: value/2.6666666666667r
33
+ 斤: value/1.6666666666667r
34
+
35
+ Time:
36
+ Planck time, tp: value*5.39121E-44.rationalize
37
+ au: value*4.1341373345192E+16.rationalize
38
+ min: value*60r
39
+ hour: value*3600r
40
+ day: value*86400r
41
+ week: value*604800r
42
+ month: value*2.628E+6
43
+ year: value*31535965.4396976r
44
+ century: value*3153600000r
45
+
46
+ Tempreture:
47
+ K: value
48
+ °C, degree, Celsius: "value-273.15r"
49
+ °F, Fahrenheit: "value*1.8r-459.67r"
50
+ °R, Rankine scale: "value*1.8r"
51
+
52
+ Area:
53
+ are, a: value*100r
54
+ ha: value*10000r
55
+ sq-in, in2: value*0.00064516r
56
+ sq-ft, ft2: value*0.09290304r
57
+ sq-yd, yd2: value*0.83612736r
58
+ rood, ro: value*1011.7141056r
59
+ acre, ac: value*4046.8564224r
60
+ sq-mi, mi2: value*2589988.110336r
61
+ 坪: value*3.3057851239669r
62
+ 畝: value*99.173553719008r
63
+ 反: value*991.73553719008r
64
+ 町: value*9917.3553719008r
65
+
66
+ Volume:
67
+ ml: value/1000000r
68
+ cl: value/100000r
69
+ dl: value/10000r
70
+ l: value/1000r
71
+ 小さじ: value*5.0E-6.rationalize
72
+ 大さじ: value*1.5E-5.rationalize
73
+ cc: value*1.0E-6.rationalize
74
+ cu-in, in3: value*1.6387064E-5.rationalize
75
+ cu-ft, ft3: value*0.028316846592r
76
+ ac-ft: value*1233.4818375475r
77
+ U.S.fluid-gallon, gallon, gal, U.S.gal, USG: value*0.003785411784r
78
+ Imperial-gallon, imp.gal: value*0.00454609r
79
+ Winchester-bushel, bushel, bsh., bu: value*0.03523907016688r
80
+ us-fluid-once, fl-oz: value*2.84130625E-5.rationalize
81
+ uk-fluid-ounce: value*2.95735295625E-5.rationalize
82
+ us-gill, gi: value*0.00011829411825r
83
+ uk-gill, uk-gi: value*0.0001420653125r
84
+ us-pint, pt: value*0.000473176473r
85
+ uk-pint, uk-pt: value*0.00056826125r
86
+ us-quart, qt: value*0.000946352946r
87
+ uk-quart, uk-qt: value*0.0011365225r
88
+ us-barrel, bbl: value*0.119240471196r
89
+ uk-barrel, uk-bbl: value*0.16365924r
90
+ 勺: value*1.8039068369647E-5.rationalize
91
+ 合: value*0.00018039068369647r
92
+ 升: value*0.0018039068369647r
93
+ 斗: value*0.018039068369647r
94
+ 石: value*0.18039068369647r
95
+
96
+ Power:
97
+ dyn: value*100000r
98
+ N: value
99
+ kgf: value*0.10197162129779r
100
+ lbf: value*0.22480894309971r
101
+ pdl: value*7.2330138512099r
102
+
103
+ Pressure, Stress:
104
+ N/mm2: value*1E-06.rationalize
105
+ bar: value*100000r
106
+ atm: value*101325r
107
+ at: value*98066.5r
108
+ kgf/cm2: value/1.0197162129779E-05.rationalize
109
+ mmH2O: value*9.80665r
110
+ cmH2O: value*98.0665r
111
+ mmH2O(3.98°C): value*9.80638r
112
+ cmH2O(3.98°C): value*98.0638r
113
+ mmHg: value*133.322387415r
114
+ inHg: value*3386.388640341r
115
+ torr: value*133.32236842105r
116
+ psi: value*6894.7572931684r
117
+
118
+ Electric power:
119
+ mW: value/1000000r
120
+ W: value/1000r
121
+ kW: value
122
+ dBm: value/60r
123
+ kgfm/s: value/101.97162129779r
124
+ PS: value/1.3596216173039r
125
+ HP: value/1.341022089595r
126
+ ft.lbf/s: value/737.56214927727r
127
+ cal/s: value/238.8458966275r
128
+ kcal/s: value/0.2388458966275r
129
+ BTU/s: value/0.94781712031332r
130
+
131
+ Energy, Work, Heat:
132
+ erg: value/10000000r
133
+ kWh: value/2.7777777777778E-07
134
+ calth: value/0.23900573613767r
135
+ kcalth: value/2.3900573613767E-04.rationalize
136
+ calIT: value/0.2388458966275r
137
+ kcalIT: value/2.388458966275E-04.rationalize
138
+ eV: value/6.2415094796077E+18.rationalize
139
+ BTU: value/9.4781712031332E-04.rationalize
140
+ ftlbf: value/0.73756214945755r
141
+ ftpdl: value/23.730360457056r
142
+ atm: value/0.0098692326671601r
143
+
144
+ Speed, Velocity:
145
+ fps: value/3.2808398950131r
146
+ fpm: value/196.85039370079r
147
+ fph: value/11811.023622047r
148
+ mps: value/0.00062137119223733r
149
+ mpm: value/0.03728227153424r
150
+ mph: value/2.2369362920544r
151
+ kn: value/1.9438444924406r
152
+ Mach: value/0.0029411764705882r
153
+
154
+ Acceleration:
155
+ km/h/s: value/3.6r
156
+ Gal: value/100r
157
+ fps2: value/3.2808398950131r
158
+ fpm/s: value/196.85039370079r
159
+ fph/s: value/11811.023622047r
160
+ mps2: value/6.2137119223733E-04.rationalize
161
+ mpm/s: value/0.03728227153424r
162
+ mph/s: value/2.2369362920544r
163
+ kn/s: value/1.9438444924406r
164
+ G: value/0.10197162129779r
165
+
166
+ Angle:
167
+ °: value
168
+ ′: value/60r
169
+ ″: value/3,600r
170
+ grad: value/1.1111111111111r
171
+ rad: value/0.017453292519943r
172
+ mil: value/17.777777777778r
173
+ /%: value/1.7455064928218r
174
+ ‰: value/17.455064928218r
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: engineer_calculator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Azeroyear
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-02 00:00:00.000000000 Z
11
+ date: 2019-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,6 +73,10 @@ files:
73
73
  - config.ru
74
74
  - engineering_calculator.gemspec
75
75
  - favicon.ico
76
+ - lib/eng_calc.rb
77
+ - lib/eng_formula.rb
78
+ - lib/eng_unit.rb
79
+ - lib/eng_unit_calc.rb
76
80
  - lib/engineer_calculator.rb
77
81
  - lib/engineer_calculator/version.rb
78
82
  - lib/unit/convert_to_japanese.yml
@@ -80,7 +84,13 @@ files:
80
84
  - lib/unit/si_alter_unit.yml
81
85
  - lib/unit/si_base_unit.yml
82
86
  - lib/unit/si_derived_unit.yml
87
+ - lib/unit/test_unit.yml
83
88
  - lib/unit/variable_unit.yml
89
+ - lib/unit_calc/metric_prefix.yml
90
+ - lib/unit_calc/si_alter_unit.yml
91
+ - lib/unit_calc/si_base_unit.yml
92
+ - lib/unit_calc/si_derived_unit.yml
93
+ - lib/unit_calc/variable_unit.yml
84
94
  homepage: https://github.com/AZeroyear/engineering_calculator
85
95
  licenses:
86
96
  - MIT