earth_power 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bfcf83d1c7b33fb9b0deaefadab26ecaf4c7982e
4
+ data.tar.gz: 8fc0f7541421954d48424cdb6005aaf12c087581
5
+ SHA512:
6
+ metadata.gz: 3933cbe61c713e9688db2b739a7817834aeb4f8fb2234e0c3a73b2deeee6c8d1d03a8ca98a4739590f698bf648c0f4ae049bc0469ac4b86648ec49424ac5c39e
7
+ data.tar.gz: d0d4270903c9bd5a05a012b45b9dabeaf602e82390df9a20113a00f6fc5cfeda5e3d5201fd584b7efc23c29864bd8f4accf921797f545981dbaa9818cf533b23
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.0.0
5
+ before_install: gem install bundler -v 1.12.5
6
+ script: bundle exec rspec
7
+ gemfile:
8
+ - Gemfile
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at kyoji-exterior@goo.jp. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in earth_power.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 K90j1
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # EarthPower
2
+ [![Build Status](https://travis-ci.org/K90j1/earth_power.svg?branch=master)](https://travis-ci.org/K90j1/earth_power)
3
+
4
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/earth_power`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+
6
+ TODO: Delete this and the text above, and describe your gem
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'earth_power'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install earth_power
23
+
24
+ ## Usage
25
+
26
+ TODO: Write usage instructions here
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/K90j1/earth_power. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
37
+
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
42
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "earth_power"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'earth_power/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'earth_power'
8
+ spec.version = EarthPower::VERSION
9
+ spec.authors = ['K90j1']
10
+ spec.email = ['mpdm.kyoji@googlemail.com']
11
+
12
+ spec.summary = %q{Calculator shipping fee for Amazon JP}
13
+ spec.description = %q{Calculator shipping fee for Amazon JP}
14
+ spec.homepage = 'https://github.com/K90j1/earth_power'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.12'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.0'
33
+ end
@@ -0,0 +1,3 @@
1
+ module EarthPower
2
+ VERSION = '0.1.3'
3
+ end
@@ -0,0 +1,282 @@
1
+ require 'earth_power/version'
2
+ #
3
+ #= EarthPower
4
+ #
5
+ #Authors:: K90j1
6
+ #Version:: 1.0 2016-03-28
7
+ #License:: MIT
8
+ #See:: https://services.amazon.co.jp/home.html
9
+ #
10
+
11
+ module EarthPower
12
+ STORAGE_COEFFICIENT = 8.126
13
+ STORAGE_VALUE = 1000
14
+ CONTRACT_FEE = 100
15
+ SIPPING_TYPE_KEYS = [0, 1, 2, 3, 4, 5, 6, 7, 8]
16
+ SIPPING_TYPE_PACKING = {0 => 525, 1 => 567, 2 => 603, 3 => 1250, 4 => 0, 5 => 87, 6 => 87, 7 => 77, 8 => 99}
17
+ SIPPING_TYPE_WEIGHT = {0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 57, 6 => 85, 7 => 166, 8 => 228}
18
+ INCHES_TO_MM = 0.254
19
+ POUNDS_TO_G = 4.53592
20
+ CARRY_OVER_KG = 6
21
+
22
+ @earnings = 0
23
+ @purchase = 0
24
+ @category = ''
25
+ @sipping_fee = 0
26
+ @storage_days = 0
27
+ @weight = 0
28
+ @weight_pattern = 0
29
+ @volume = []
30
+ @volume_pattern = 0
31
+ @total_volume = 0
32
+ @base_cost = 0
33
+ @is_fba = 0
34
+ @is_large_business = 0
35
+ @is_media = 0
36
+ @is_large_item = 0
37
+ @total_volume = 0
38
+
39
+ #
40
+ #= カテゴリー成約料
41
+ #params earnings
42
+ #params base_cost
43
+ #params purchase
44
+ #params category
45
+ #params sipping_fee
46
+ #params is_fba
47
+ #params is_large_business
48
+ #params is_media
49
+ #params storage_days
50
+ #params weight
51
+ #params volume[]
52
+ #
53
+
54
+ def initialize(earnings, base_cost, purchase, category, sipping_fee, is_fba, is_large_business, is_media, storage_days, weight, volume)
55
+ @earnings = earnings.to_i
56
+ @purchase = purchase.to_i
57
+ @category = category
58
+ @sipping_fee = sipping_fee.to_i
59
+ @is_fba = is_fba.to_i
60
+ @is_media = is_media.to_i
61
+ @volume = volume.clone
62
+ @volume_pattern = get_volume_pattern volume
63
+ @weight = weight.to_i
64
+ @weight_pattern = get_weight_pattern weight.to_i
65
+ @storage_days = storage_days.to_i
66
+ @is_large_business = is_large_business.to_i
67
+ @base_cost = base_cost.to_i
68
+ @total_volume = @volume[0].to_f * @volume[1].to_f * @volume[2].to_f / 1000
69
+ end
70
+
71
+ def get_profit
72
+ return 0 if @earnings == 0
73
+ contract_fee = get_contract_fee
74
+ category_fee = get_category_fee
75
+ sales_charge = get_sales_charge
76
+ storage_fee = 0
77
+ agent_sipping_fee = 0
78
+ if @is_fba == 1
79
+ storage_fee = get_storage_fee
80
+ agent_sipping_fee = get_agent_sipping_fee
81
+ end
82
+ result = @earnings - @purchase - contract_fee - category_fee - sales_charge -storage_fee - agent_sipping_fee - @base_cost - @sipping_fee
83
+ result.ceil
84
+ end
85
+
86
+ def self.get_default_volume(value)
87
+ case value.to_i
88
+ when 0
89
+ return [250, 180, 20]
90
+ when 1
91
+ return [450, 350, 200]
92
+ when 2
93
+ return [300, 300, 400]
94
+ when 3
95
+ return [400, 400, 600]
96
+ when 4
97
+ return [500, 500, 700]
98
+ else
99
+ return [600, 600, 800]
100
+ end
101
+ end
102
+
103
+ def self.get_default_weight(value)
104
+ case value.to_i
105
+ when 0
106
+ return 249
107
+ when 1
108
+ return 4500
109
+ else
110
+ return 9000
111
+ end
112
+ end
113
+
114
+ def self.convert_inches_mm(value)
115
+ value.to_f * INCHES_TO_MM.to_f
116
+ end
117
+
118
+ def self.convert_pounds_g(value)
119
+ value.to_f * POUNDS_TO_G.to_f
120
+ end
121
+
122
+ #
123
+ #= WEIGHT PATTERN
124
+ # 250g未満, 9kg未満, 9kg以上
125
+ #
126
+ def get_weight_pattern(weight)
127
+ if weight < 250
128
+ 0
129
+ elsif weight < 9000
130
+ 1
131
+ else
132
+ 2
133
+ end
134
+ end
135
+
136
+ #
137
+ #= VOLUME PATTERN
138
+ #params Array[height, length, width]
139
+ # 25x18x2, 45x35x20, 100(30x30x40), 140(40x40x60), 170(50x50x70), 200(60x60x80)
140
+ #
141
+ def get_volume_pattern(volume)
142
+ return 0 if recursive_measuring(volume, [250, 180, 20])
143
+ return 1 if recursive_measuring(volume, [450, 350, 200])
144
+ return 2 if recursive_measuring(volume, [300, 300, 400])
145
+ return 3 if recursive_measuring(volume, [400, 400, 600])
146
+ return 4 if recursive_measuring(volume, [500, 500, 700])
147
+ 5
148
+ end
149
+
150
+ private
151
+ def recursive_measuring(exactly, expected)
152
+ return true if exactly.empty?
153
+ result = false
154
+ exactly.each_with_index do |value, key|
155
+ expected.each_with_index do |pattern, pattern_key|
156
+ if value <= pattern
157
+ exactly.delete_at key
158
+ expected.delete_at pattern_key
159
+ result = recursive_measuring(exactly, expected)
160
+ end
161
+ end
162
+ end
163
+ result
164
+ end
165
+
166
+ #
167
+ #= カテゴリー成約料
168
+ #see https://www.amazon.co.jp/gp/help/customer/display.html?nodeId=1085246
169
+ #
170
+ def get_category_fee
171
+ case @category
172
+ when '本', '洋書', 'コミック', '雑誌', '古本・古書'
173
+ @is_media = 1
174
+ category_fee = 60
175
+ when 'ミュージック', 'DVD', 'PCソフト', 'ゲーム'
176
+ @is_media = 1
177
+ category_fee = 140
178
+ when 'VHS'
179
+ @is_media = 1
180
+ category_fee = 30
181
+ else
182
+ @is_media = 0
183
+ # category_fee = 100
184
+ category_fee = 0
185
+ end
186
+ category_fee
187
+ end
188
+
189
+ #
190
+ #= 販売手数料
191
+ #see https://www.amazon.co.jp/gp/help/customer/display.html?nodeId=1085246
192
+ #
193
+ def get_sales_charge
194
+ earnings = @earnings
195
+ case @category
196
+ when '大型家電', 'パソコン・周辺機器', '楽器・音響機器'
197
+ charge = earnings.to_i * 0.08
198
+ when '本', '洋書', 'コミック', '雑誌', '古本・古書', 'ミュージック', 'VHS', 'DVD', 'ゲーム', 'PCソフト', '文房具・オフィス用品', 'ホーム&キッチン', 'DIY・工具', 'ホビー', 'おもちゃ', 'スポーツ&アウトドア', '車&バイク', 'ベビー&マタニティ'
199
+ charge = earnings.to_i * 0.15
200
+ when 'Kindleストア'
201
+ charge = earnings.to_i * 0.45
202
+ else
203
+ charge = earnings.to_i * 0.10
204
+ end
205
+ charge
206
+ end
207
+
208
+ #
209
+ #= 基本成約料
210
+ #
211
+ def get_contract_fee
212
+ return 0 if @is_large_business == 1
213
+ CONTRACT_FEE
214
+ end
215
+
216
+ #
217
+ #= 在庫保管手数料
218
+ #
219
+ def get_storage_fee
220
+ STORAGE_COEFFICIENT.to_f * ((@total_volume) / STORAGE_VALUE.to_f) * @storage_days
221
+ end
222
+
223
+ #
224
+ #= 配送代行手数料
225
+ # 出荷作業手数料
226
+ # 発送重量手数料
227
+ #
228
+ def get_agent_sipping_fee
229
+ type = get_agent_sipping_type
230
+ weight = SIPPING_TYPE_WEIGHT[type]
231
+ coefficient = 0
232
+ if (type == 6 || type == 8) && (@weight - 2000) > 0
233
+ coefficient = (@weight - 2000) / 1000
234
+ end
235
+ weight += coefficient.ceil * CARRY_OVER_KG.to_i
236
+ # ApiRequest.logging("出荷作業手数料 #{SIPPING_TYPE_PACKING[type]}")
237
+ # ApiRequest.logging("発送重量手数料 #{weight}")
238
+ SIPPING_TYPE_PACKING[type].to_i + weight.to_i
239
+ end
240
+
241
+ def is_expensive
242
+ return true if @earnings > 45000 && @is_large_item == 0
243
+ false
244
+ end
245
+
246
+ #
247
+ #= 区分
248
+ # 大型区分1, 大型区分2, 大型区分3, 特殊大型, 高額商品, メディア小型, メディア標準, メディア以外小型, メディア以外標準
249
+ #
250
+ def get_agent_sipping_type
251
+ if @weight_pattern == 2
252
+ @is_large_item = true
253
+ case @volume_pattern
254
+ when 3
255
+ return SIPPING_TYPE_KEYS[1]
256
+ when 4
257
+ return SIPPING_TYPE_KEYS[2]
258
+ when 5
259
+ return SIPPING_TYPE_KEYS[3]
260
+ else
261
+ return SIPPING_TYPE_KEYS[0]
262
+ end
263
+ end
264
+ if is_expensive
265
+ return SIPPING_TYPE_KEYS[4]
266
+ end
267
+ if @is_media == 1
268
+ case @volume_pattern
269
+ when 0
270
+ return SIPPING_TYPE_KEYS[5]
271
+ else
272
+ return SIPPING_TYPE_KEYS[6]
273
+ end
274
+ end
275
+ case @volume_pattern
276
+ when 0
277
+ return SIPPING_TYPE_KEYS[7]
278
+ else
279
+ return SIPPING_TYPE_KEYS[8]
280
+ end
281
+ end
282
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: earth_power
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - K90j1
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-01 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Calculator shipping fee for Amazon JP
56
+ email:
57
+ - mpdm.kyoji@googlemail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - earth_power.gemspec
73
+ - lib/earth_power.rb
74
+ - lib/earth_power/version.rb
75
+ homepage: https://github.com/K90j1/earth_power
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.6.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Calculator shipping fee for Amazon JP
99
+ test_files: []