shioconv 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +9 -0
- data/config/condiments.rb +25 -0
- data/config/condiments.yaml +171 -0
- data/lib/shioconv/condiment.rb +36 -0
- data/lib/shioconv/unit.rb +64 -0
- data/lib/shioconv/version.rb +3 -0
- data/lib/shioconv.rb +31 -0
- data/shioconv.gemspec +24 -0
- data/spec/shioconv/unit_spec.rb +16 -0
- data/spec/shioconv_spec.rb +100 -0
- data/spec/spec_helper.rb +4 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f61eb16a780a38b34e99d8b26090c0925f161ffd
|
4
|
+
data.tar.gz: b7aa1e9ec47530035666203b279062239744fd0d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 98a0d12b6d9e3e458d9ef9ebbc5d92309a97523fdd2518c89ed16ef5a03add5db4b2bb559f47b810ef7882fd364b2fbde3bdb229108706a628ce3b92444eabdd
|
7
|
+
data.tar.gz: 2346c916108d4e4a12c3926e0c4950d12719f698f25ef4f9a061172511aa03ba007d70de4aa4d6f6d46740d25cf2298b75fa8453d4f1c440d6a3834fe5fd82f6
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
config/condiments.tsv
|
24
|
+
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 SHIOYA, Hiromu
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Shioconv
|
2
|
+
|
3
|
+
convert between cubic contents and weight for typcal seasonings.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'shioconv'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install shioconv
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
* convert amount of condiments between units
|
22
|
+
|
23
|
+
```
|
24
|
+
salt = Shioconv.measure(:salt, 1, :tbsp)
|
25
|
+
|
26
|
+
salt.to_cc # => 15.0
|
27
|
+
salt.to_g # => 18.0
|
28
|
+
```
|
29
|
+
|
30
|
+
* show all condiments and units
|
31
|
+
|
32
|
+
```
|
33
|
+
Shioconv::Condiment.list # => returns array of string
|
34
|
+
Shioconv::Unit.list # => returns array of string
|
35
|
+
```
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it ( https://github.com/kwappa/shioconv/fork )
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
csv = CSV.read('./condiments.tsv', col_sep: "\t")
|
5
|
+
csv.shift # drop title row
|
6
|
+
|
7
|
+
result = csv.each_with_object([]) do |cols, r|
|
8
|
+
(key, japanese_name, english_name, specific_gravity, *synonyms) = cols.map(&:to_s)
|
9
|
+
next if key.empty?
|
10
|
+
synonyms = synonyms.find_all { |al| !al.empty? }.map(&:downcase)
|
11
|
+
|
12
|
+
r << {
|
13
|
+
key: key.to_sym,
|
14
|
+
japanese_name: japanese_name,
|
15
|
+
english_name: english_name,
|
16
|
+
specific_gravity: specific_gravity.to_f,
|
17
|
+
synonyms: synonyms
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
File.open('./condiments.yaml', 'w') { |yaml|
|
22
|
+
yaml.write YAML.dump(result)
|
23
|
+
}
|
24
|
+
|
25
|
+
p result
|
@@ -0,0 +1,171 @@
|
|
1
|
+
---
|
2
|
+
- :key: :water
|
3
|
+
:japanese_name: "水"
|
4
|
+
:english_name: water
|
5
|
+
:specific_gravity: 1.0
|
6
|
+
:synonyms: []
|
7
|
+
- :key: :sake
|
8
|
+
:japanese_name: "酒"
|
9
|
+
:english_name: sake
|
10
|
+
:specific_gravity: 1.0
|
11
|
+
:synonyms:
|
12
|
+
- "日本酒"
|
13
|
+
- :key: :wine
|
14
|
+
:japanese_name: "ワイン"
|
15
|
+
:english_name: wine
|
16
|
+
:specific_gravity: 1.0
|
17
|
+
:synonyms: []
|
18
|
+
- :key: :vinegar
|
19
|
+
:japanese_name: "酢"
|
20
|
+
:english_name: vinegar
|
21
|
+
:specific_gravity: 1.0
|
22
|
+
:synonyms: []
|
23
|
+
- :key: :soy_source
|
24
|
+
:japanese_name: "しょうゆ"
|
25
|
+
:english_name: soy source
|
26
|
+
:specific_gravity: 1.15
|
27
|
+
:synonyms:
|
28
|
+
- "醤油"
|
29
|
+
- :key: :sweet_sake
|
30
|
+
:japanese_name: "本みりん"
|
31
|
+
:english_name: sweet dake
|
32
|
+
:specific_gravity: 1.15
|
33
|
+
:synonyms:
|
34
|
+
- "味醂"
|
35
|
+
- :key: :fake_sweet_sake
|
36
|
+
:japanese_name: "みりん風調味料"
|
37
|
+
:english_name: fake sweet sake
|
38
|
+
:specific_gravity: 1.25
|
39
|
+
:synonyms: []
|
40
|
+
- :key: :soybean_paste
|
41
|
+
:japanese_name: "みそ"
|
42
|
+
:english_name: soybean paste
|
43
|
+
:specific_gravity: 1.15
|
44
|
+
:synonyms:
|
45
|
+
- "味噌"
|
46
|
+
- :key: :sea_salt
|
47
|
+
:japanese_name: "粗塩"
|
48
|
+
:english_name: sea salt
|
49
|
+
:specific_gravity: 0.9
|
50
|
+
:synonyms:
|
51
|
+
- "あら塩"
|
52
|
+
- :key: :salt
|
53
|
+
:japanese_name: "食塩"
|
54
|
+
:english_name: salt
|
55
|
+
:specific_gravity: 1.2
|
56
|
+
:synonyms:
|
57
|
+
- "塩"
|
58
|
+
- :key: :refined_salt
|
59
|
+
:japanese_name: "精製塩"
|
60
|
+
:english_name: refined salt
|
61
|
+
:specific_gravity: 1.2
|
62
|
+
:synonyms:
|
63
|
+
- "焼き塩"
|
64
|
+
- :key: :castor_sugar
|
65
|
+
:japanese_name: "上白糖"
|
66
|
+
:english_name: castor sugar
|
67
|
+
:specific_gravity: 0.65
|
68
|
+
:synonyms:
|
69
|
+
- "砂糖"
|
70
|
+
- :key: :granulated_sugar
|
71
|
+
:japanese_name: "グラニュー糖"
|
72
|
+
:english_name: granulated sugar
|
73
|
+
:specific_gravity: 0.9
|
74
|
+
:synonyms: []
|
75
|
+
- :key: :brown_sugar
|
76
|
+
:japanese_name: "ざらめ"
|
77
|
+
:english_name: brown sugar
|
78
|
+
:specific_gravity: 1.0
|
79
|
+
:synonyms:
|
80
|
+
- "粗目"
|
81
|
+
- :key: :starch_syrup
|
82
|
+
:japanese_name: "水あめ"
|
83
|
+
:english_name: starch syrup
|
84
|
+
:specific_gravity: 1.4
|
85
|
+
:synonyms:
|
86
|
+
- "水飴"
|
87
|
+
- :key: :honey
|
88
|
+
:japanese_name: "はちみつ"
|
89
|
+
:english_name: honey
|
90
|
+
:specific_gravity: 1.4
|
91
|
+
:synonyms:
|
92
|
+
- "蜂蜜"
|
93
|
+
- :key: :jam
|
94
|
+
:japanese_name: "ジャム"
|
95
|
+
:english_name: jam
|
96
|
+
:specific_gravity: 1.25
|
97
|
+
:synonyms:
|
98
|
+
- "ママレード"
|
99
|
+
- :key: :marmalade
|
100
|
+
:japanese_name: "マーマレード"
|
101
|
+
:english_name: marmalade
|
102
|
+
:specific_gravity: 1.35
|
103
|
+
:synonyms: []
|
104
|
+
- :key: :oil
|
105
|
+
:japanese_name: "油"
|
106
|
+
:english_name: oil
|
107
|
+
:specific_gravity: 0.9
|
108
|
+
:synonyms:
|
109
|
+
- "サラダ油"
|
110
|
+
- "サラダオイル"
|
111
|
+
- "オイル"
|
112
|
+
- :key: :butter
|
113
|
+
:japanese_name: "バター"
|
114
|
+
:english_name: butter
|
115
|
+
:specific_gravity: 0.9
|
116
|
+
:synonyms: []
|
117
|
+
- :key: :margarine
|
118
|
+
:japanese_name: "マーガリン"
|
119
|
+
:english_name: margarine
|
120
|
+
:specific_gravity: 0.9
|
121
|
+
:synonyms: []
|
122
|
+
- :key: :lard
|
123
|
+
:japanese_name: "ラード"
|
124
|
+
:english_name: lard
|
125
|
+
:specific_gravity: 0.85
|
126
|
+
:synonyms: []
|
127
|
+
- :key: :shortening
|
128
|
+
:japanese_name: "ショートニング"
|
129
|
+
:english_name: shortening
|
130
|
+
:specific_gravity: 0.8
|
131
|
+
:synonyms: []
|
132
|
+
- :key: :cornstarch
|
133
|
+
:japanese_name: "コーンスターチ"
|
134
|
+
:english_name: cornstarch
|
135
|
+
:specific_gravity: 0.5
|
136
|
+
:synonyms: []
|
137
|
+
- :key: :flour
|
138
|
+
:japanese_name: "小麦粉"
|
139
|
+
:english_name: flour
|
140
|
+
:specific_gravity: 0.55
|
141
|
+
:synonyms:
|
142
|
+
- strong_flour
|
143
|
+
- medium_flour
|
144
|
+
- weak_flour
|
145
|
+
- :key: :starch
|
146
|
+
:japanese_name: "片栗粉"
|
147
|
+
:english_name: starch
|
148
|
+
:specific_gravity: 0.65
|
149
|
+
:synonyms: []
|
150
|
+
- :key: :milk
|
151
|
+
:japanese_name: "牛乳"
|
152
|
+
:english_name: milk
|
153
|
+
:specific_gravity: 1.05
|
154
|
+
:synonyms: []
|
155
|
+
- :key: :cream
|
156
|
+
:japanese_name: "生クリーム"
|
157
|
+
:english_name: cream
|
158
|
+
:specific_gravity: 1.0
|
159
|
+
:synonyms: []
|
160
|
+
- :key: :ketchup
|
161
|
+
:japanese_name: "ケチャップ"
|
162
|
+
:english_name: ketchup
|
163
|
+
:specific_gravity: 1.15
|
164
|
+
:synonyms:
|
165
|
+
- "トマトケチャップ"
|
166
|
+
- :key: :worcestershire_sauce
|
167
|
+
:japanese_name: "ウスターソース"
|
168
|
+
:english_name: worcestershire sauce
|
169
|
+
:specific_gravity: 1.2
|
170
|
+
:synonyms:
|
171
|
+
- "ソース"
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Shioconv::Condiment < OpenStruct
|
2
|
+
def self.find_by(condiment)
|
3
|
+
# find by key
|
4
|
+
if condiment.is_a?(Symbol)
|
5
|
+
result = raw_data.find { |data| data[:key] == condiment }
|
6
|
+
return self.new(result) if result
|
7
|
+
end
|
8
|
+
|
9
|
+
# find by name
|
10
|
+
condiment = condiment.to_s.downcase
|
11
|
+
[:japanese_name, :english_name].each do |key|
|
12
|
+
result = raw_data.find { |data| data[key] == condiment }
|
13
|
+
return self.new(result) if result
|
14
|
+
end
|
15
|
+
|
16
|
+
# find by synonyms
|
17
|
+
result = raw_data.find { |data| data[:synonyms].include?(condiment) }
|
18
|
+
return self.new(result) if result
|
19
|
+
|
20
|
+
raise ArgumentError.new("condiment '#{condiment}' does not found.")
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.data_file
|
24
|
+
File.join(File.dirname(File.expand_path(__FILE__)), %w(.. .. config condiments.yaml))
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.raw_data
|
28
|
+
@@raw_data ||= YAML.parse(File.read(data_file)).to_ruby
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.list
|
32
|
+
raw_data.map do |datum|
|
33
|
+
"#{sprintf('%-16s', datum[:key])} : 「#{datum[:japanese_name]}(#{datum[:english_name]})」"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class Shioconv::Unit
|
2
|
+
attr_reader :type, :name, :value
|
3
|
+
|
4
|
+
UNIT_TYPES = {
|
5
|
+
volume: {
|
6
|
+
cc: 1.0,
|
7
|
+
ml: 1.0,
|
8
|
+
tbsp: 15.0,
|
9
|
+
tsp: 5.0,
|
10
|
+
cup: 200.0,
|
11
|
+
us_cup: 236.56,
|
12
|
+
jp_cup: 200.0,
|
13
|
+
},
|
14
|
+
weight: {
|
15
|
+
g: 1.0,
|
16
|
+
kg: 1000.0,
|
17
|
+
oz: 28.349,
|
18
|
+
lb: 453.592,
|
19
|
+
},
|
20
|
+
}.freeze
|
21
|
+
|
22
|
+
CONVERTABLE_UNITS = UNIT_TYPES.map { |_, units| units.keys }.flatten.freeze
|
23
|
+
|
24
|
+
def self.find_by(unit_name)
|
25
|
+
UNIT_TYPES.each do |unit_type, units|
|
26
|
+
if units.has_key?(unit_name)
|
27
|
+
return self.new(type: unit_type, name: unit_name, value: units[unit_name])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
raise ArgumentError.new("unit [#{unit_name}] does not found.") unless @name
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.convertable?(unit)
|
35
|
+
CONVERTABLE_UNITS.include?(unit)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.list
|
39
|
+
UNIT_TYPES.map do |type, units|
|
40
|
+
(base_unit, _) = units.shift
|
41
|
+
"#{type}: #{base_unit}, " << units.map { |unit, value| "#{unit}(#{value}#{base_unit})" }.join(', ')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def initialize(type: type, name: name, value: value)
|
46
|
+
@type = type
|
47
|
+
@name = name
|
48
|
+
@value = value
|
49
|
+
end
|
50
|
+
|
51
|
+
def convert(condiment, quantity, dst_unit)
|
52
|
+
return quantity if name == dst_unit
|
53
|
+
dst_unit = self.class.find_by(dst_unit)
|
54
|
+
|
55
|
+
current_vavlue = quantity * value / dst_unit.value
|
56
|
+
if type == :weight && dst_unit.type == :volume
|
57
|
+
current_vavlue /= condiment.specific_gravity
|
58
|
+
elsif type == :volume && dst_unit.type == :weight
|
59
|
+
current_vavlue *= condiment.specific_gravity
|
60
|
+
end
|
61
|
+
|
62
|
+
current_vavlue
|
63
|
+
end
|
64
|
+
end
|
data/lib/shioconv.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
require_relative "shioconv/version"
|
5
|
+
require_relative "shioconv/unit"
|
6
|
+
require_relative "shioconv/condiment"
|
7
|
+
|
8
|
+
class Shioconv
|
9
|
+
attr_reader :condiment, :quantity, :unit
|
10
|
+
|
11
|
+
def self.measure(condiment_name, quantity, unit_name)
|
12
|
+
condiment = Condiment.find_by(condiment_name)
|
13
|
+
unit = Unit.find_by(unit_name)
|
14
|
+
|
15
|
+
self.new(condiment: condiment, quantity: quantity, unit: unit)
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(condiment: condiment, quantity: quantity, unit: unit)
|
19
|
+
@condiment = condiment
|
20
|
+
@quantity = quantity
|
21
|
+
@unit = unit
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_missing(name, *args)
|
25
|
+
return super unless m = /\Ato_(?<dst_unit>\w+)\Z/.match(name)
|
26
|
+
dst_unit = m[:dst_unit].to_sym
|
27
|
+
return super unless Unit.convertable?(dst_unit)
|
28
|
+
|
29
|
+
@unit.convert(@condiment, @quantity, dst_unit)
|
30
|
+
end
|
31
|
+
end
|
data/shioconv.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'shioconv/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "shioconv"
|
8
|
+
spec.version = Shioconv::VERSION
|
9
|
+
spec.authors = ["SHIOYA, Hiromu"]
|
10
|
+
spec.email = ["kwappa.856@gmail.com"]
|
11
|
+
spec.summary = %q{Shioconv converts between weight and volume of typical condiments.}
|
12
|
+
spec.description = %q{Shioconv converts between weight and volume of typical condiments.}
|
13
|
+
spec.homepage = "http://github.com/kwappa/shioconv"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shioconv::Unit do
|
4
|
+
let(:convertable_unit) { :g }
|
5
|
+
let(:not_convertable_unit) { :not_convertable_unit }
|
6
|
+
|
7
|
+
describe '.convertable?' do
|
8
|
+
context 'when convertable unit given' do
|
9
|
+
specify { expect(described_class.convertable?(convertable_unit)).to be_true }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'when not convertable unit given' do
|
13
|
+
specify { expect(described_class.convertable?(not_convertable_unit)).to be_false }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shioconv do
|
4
|
+
let(:invalid_condiment_name) { :invalid_condiment }
|
5
|
+
let(:invalid_unit_name) { :invalid_unit }
|
6
|
+
|
7
|
+
describe '.measure' do
|
8
|
+
context 'if invalid condiment_name given' do
|
9
|
+
specify { expect { Shioconv.measure(invalid_condiment_name, 1, :tbsp) }.to raise_error ArgumentError }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'if invalid unit name given' do
|
13
|
+
specify { expect { Shioconv.measure(:salt, 1, invalid_unit_name) }.to raise_error ArgumentError }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#method_missing' do
|
18
|
+
subject(:salt) { Shioconv.measure(:salt, 1, :tbsp) }
|
19
|
+
|
20
|
+
shared_examples 'does not define instance method' do
|
21
|
+
it 'does not define instance method' do
|
22
|
+
expect(described_class.instance_methods(false)).to_not be_include(superclass_method)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when called method that does not start with "to_"' do
|
27
|
+
let(:superclass_method) { :frozen? }
|
28
|
+
include_examples 'does not define instance method'
|
29
|
+
it 'delegates to superclass' do
|
30
|
+
expect(salt.send(superclass_method)).to be_false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when called metod that starts with "to_" but not defined at self' do
|
35
|
+
let(:superclass_method) { :to_s }
|
36
|
+
include_examples 'does not define instance method'
|
37
|
+
it 'delegates to superclass' do
|
38
|
+
expect(salt.send(superclass_method)).to be_a(String)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when called method that does not start with "to_" and not defined at all' do
|
43
|
+
let(:superclass_method) { :invalid_method_name }
|
44
|
+
include_examples 'does not define instance method'
|
45
|
+
it 'raises NoMethodError' do
|
46
|
+
expect { salt.send(superclass_method) }.to raise_error NoMethodError
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'when called method that starts with "to_" and not defined at all' do
|
51
|
+
let(:superclass_method) { :to_invalid_method_name }
|
52
|
+
include_examples 'does not define instance method'
|
53
|
+
it 'raises NoMethodError' do
|
54
|
+
expect { salt.send(superclass_method) }.to raise_error NoMethodError
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when called convertable method' do
|
59
|
+
context 'from weight' do
|
60
|
+
subject(:soy_source) { Shioconv.measure(:soy_source, 10, :g) }
|
61
|
+
|
62
|
+
context 'to weight' do
|
63
|
+
it 'converts correctly from g to kg' do
|
64
|
+
expect(soy_source.to_kg).to be_within(0.01).of(0.01)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'converts correctly from g to oz' do
|
68
|
+
expect(soy_source.to_oz).to be_within(0.01).of(0.3527)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'to volume' do
|
73
|
+
it 'converts correctly from g to tbsp' do
|
74
|
+
expect(soy_source.to_tbsp).to be_within(0.01).of(0.5797)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'from value' do
|
80
|
+
subject(:soy_source) { Shioconv.measure(:soy_source, 15, :cc) }
|
81
|
+
|
82
|
+
context 'to volume' do
|
83
|
+
it 'converts correctly from cc to tbsp' do
|
84
|
+
expect(soy_source.to_tbsp).to be_within(0.01).of(1)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'converts correctly from cc to us_cpu' do
|
88
|
+
expect(soy_source.to_us_cup).to be_within(0.01).of(0.0634)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'to weight' do
|
93
|
+
it 'converts correctly from cc to g' do
|
94
|
+
expect(soy_source.to_g).to be_within(0.01).of(17.25)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shioconv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SHIOYA, Hiromu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Shioconv converts between weight and volume of typical condiments.
|
56
|
+
email:
|
57
|
+
- kwappa.856@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- config/condiments.rb
|
68
|
+
- config/condiments.yaml
|
69
|
+
- lib/shioconv.rb
|
70
|
+
- lib/shioconv/condiment.rb
|
71
|
+
- lib/shioconv/unit.rb
|
72
|
+
- lib/shioconv/version.rb
|
73
|
+
- shioconv.gemspec
|
74
|
+
- spec/shioconv/unit_spec.rb
|
75
|
+
- spec/shioconv_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
homepage: http://github.com/kwappa/shioconv
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.2.2
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Shioconv converts between weight and volume of typical condiments.
|
101
|
+
test_files:
|
102
|
+
- spec/shioconv/unit_spec.rb
|
103
|
+
- spec/shioconv_spec.rb
|
104
|
+
- spec/spec_helper.rb
|