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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17a5f042f8929c5816f4a0e01732fd8410e28208
4
- data.tar.gz: 64a19edf86ea197ca358d7b890f12e661a80ee17
3
+ metadata.gz: 7c1daa187c1b53ef63fa34a45816afa499a2bd0e
4
+ data.tar.gz: f94a884d86d515e7549c91d76152ca017b989c1b
5
5
  SHA512:
6
- metadata.gz: 4e437160671901ccf31792158d7b6d94e27df784c53bcce8a75773aa5701190a04af9af3aeb673bc9d2a0140afa902cfad2eae85e2251b1620a6835bc3abf015
7
- data.tar.gz: 351e197a215c9a8ad39e9bda4288f3398d89b370a591655c2915d8d733968135cb18bd45c4c18efc10c0b876edfa1662bfe427793d0eca95c1fecc354285da4b
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 = comma($1) + $2
50
+ result = ja($1) + $2
51
51
  else
52
- result = comma(s)
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
- TYPE_JA = 3
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
- result << UnitConverterResult.create_number(value)
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
@@ -1,3 +1,3 @@
1
1
  module Libruby
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - src