libruby 0.4.0 → 0.4.1
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 +4 -4
- data/lib/libruby/unit_converter.rb +21 -8
- data/lib/libruby/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c1daa187c1b53ef63fa34a45816afa499a2bd0e
|
4
|
+
data.tar.gz: f94a884d86d515e7549c91d76152ca017b989c1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1271bb93422f0e2ec53f68bbd2b0343008cd142e5e98043a74e1fa2f419bed61bfc9f2f36dd0c9e740bf71ee627ad0f5d068df93c1c78624a1d5dc9e84e6d50
|
7
|
+
data.tar.gz: 9470fd7be9e5f3092b2caf67fe585a8c27dd2a64747818aaa65ce212ecd5854115f0d2377d6962fb514f5897660c5573b687894aa48400613c7dbf93fdc50883
|
@@ -47,9 +47,9 @@ module Libruby
|
|
47
47
|
def self.to_ja_s(num)
|
48
48
|
s = to_s(num)
|
49
49
|
if s =~ /(\d+)(\.\d+)/
|
50
|
-
result =
|
50
|
+
result = ja($1) + $2
|
51
51
|
else
|
52
|
-
result =
|
52
|
+
result = ja(s)
|
53
53
|
end
|
54
54
|
result
|
55
55
|
end
|
@@ -59,23 +59,31 @@ module Libruby
|
|
59
59
|
class UnitConverterResult
|
60
60
|
TYPE_ORIGINAL = 1
|
61
61
|
TYPE_NUMBER = 2
|
62
|
-
|
62
|
+
TYPE_EN = 3
|
63
|
+
TYPE_JA = 4
|
63
64
|
|
64
|
-
TYPE_LABELS =
|
65
|
+
TYPE_LABELS = {
|
65
66
|
TYPE_ORIGINAL => 'オリジナル',
|
66
67
|
TYPE_NUMBER => '数値表現',
|
67
68
|
TYPE_JA => '日本語表現'
|
68
|
-
|
69
|
+
}
|
70
|
+
|
71
|
+
def self.find(results, type)
|
72
|
+
results.find{|result| result.type == type}
|
73
|
+
end
|
69
74
|
|
70
75
|
def self.create_original(value)
|
71
76
|
UnitConverterResult.new(TYPE_ORIGINAL, value)
|
72
77
|
end
|
73
78
|
|
74
79
|
def self.create_number(value)
|
75
|
-
# ほんとはカンマ区切りにしたい整数部と小数部にわけて三桁区切りにする必要あり?
|
76
80
|
UnitConverterResult.new(TYPE_NUMBER, UnitConverterUtils.to_comma_s(value))
|
77
81
|
end
|
78
82
|
|
83
|
+
def self.create_ja(value)
|
84
|
+
UnitConverterResult.new(TYPE_JA, UnitConverterUtils.to_ja_s(value))
|
85
|
+
end
|
86
|
+
|
79
87
|
def initialize(type, value)
|
80
88
|
@type = type
|
81
89
|
@value = value
|
@@ -83,7 +91,11 @@ module Libruby
|
|
83
91
|
attr_reader :type, :value
|
84
92
|
|
85
93
|
def type_label
|
86
|
-
TYPE_LABELS[type]
|
94
|
+
TYPE_LABELS[@type]
|
95
|
+
end
|
96
|
+
|
97
|
+
def to_s
|
98
|
+
"#{@type}:#{type_label}:#{value}"
|
87
99
|
end
|
88
100
|
end
|
89
101
|
|
@@ -123,7 +135,8 @@ module Libruby
|
|
123
135
|
original_num = get_num(value)
|
124
136
|
unit = get_unit(value)
|
125
137
|
num = calc_num(original_num, unit)
|
126
|
-
|
138
|
+
results << UnitConverterResult.create_number(num)
|
139
|
+
results << UnitConverterResult.create_ja(num)
|
127
140
|
rescue ArgumentError => e
|
128
141
|
puts e.to_s
|
129
142
|
end
|
data/lib/libruby/version.rb
CHANGED