
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
WithTaxはクラスにextendし、.attr_with_tax
で属性を指定すると、#(指定した属性)_with_tax
というメソッドで税込金額を求められるようになります。
Gemfileに下のように記述してください。
gem 'with_tax'
それから下を実行してください:
$ bundle install
または自分でインストールするには:
$ gem install with_tax
下のようにWithTax
をextend
し、attr_with_tax
で対象の属性を指定してください。
class SampleItem
extend WithTax
attr_accessor :name, :price
attr_with_tax :price
def initialize(name, price)
@name = name
@price = price
end
end
そうすると下のように属性名_with_tax
というメソッドが利用できるようになり、税込み価格が取得できます。小数点以下は切り上げになっています。
sample_item = SampleItem.new('Some item', 123)
sample_item.price # => 123
sample_item.price_with_tax #=> 136
税率改定があるときに、計算の基準になる日を指定することもできます。
sample_item = SampleItem.new('Some item', 123)
sample_item.price # => 123
sample_item.price_with_tax(Date.parse('2019/09/30')) #=> 132
デフォルトでは切り上げになっていますが、rounding_method
を設定することで切り替えることができます。
class SampleItem
extend WithTax
attr_accessor :name, :price
attr_with_tax :price, rounding_method: :floor
def initialize(name, price)
@name = name
@price = price
end
end
:floor
を設定すると小数点以下を切り捨てます。
class SampleItem
extend WithTax
attr_accessor :name, :price
attr_with_tax :price, rounding_method: :floor
def initialize(name, price)
@name = name
@price = price
end
end
sample_item1 = SampleItem.new('Sample Item', 123)
sample_item1.price #=> 123
sample_item1.price_with_tax #=> 135
sample_item2 = SampleItem.new('Sample Item', 345)
sample_item2.price #=> 345
sample_item2.price_with_tax #=> 379
:round
を設定すると小数点以下を四捨五入します。
class SampleItem
extend WithTax
attr_accessor :name, :price
attr_with_tax :price, rounding_method: :round
def initialize(name, price)
@name = name
@price = price
end
end
sample_item1 = SampleItem.new('Sample Item', 345)
sample_item1.price #=> 123
sample_item1.price_with_tax #=> 135
sample_item2 = SampleItem.new('Sample Item', 345)
sample_item2.price #=> 345
sample_item2.price_with_tax #=> 380
nil
を設定すると小数点以下を処理しません。
class SampleItem
extend WithTax
attr_accessor :name, :price
attr_with_tax :price, rounding_method: nil
def initialize(name, price)
@name = name
@price = price
end
end
sample_item.price #=> 123
sample_item.price_with_tax #=> 135.3
デフォルトでは10%
ですが、rate_type
に:reduced
を設定することで軽減税率の8%に切り替えることができます。
class SampleItem
extend WithTax
attr_accessor :name, :price
attr_with_tax :price, rate_type: :reduced
def initialize(name, price)
@name = name
@price = price
end
end
sample_item.price #=> 123
sample_item.price_with_tax #=> 133
attr_with_max
は複数のオプションも設定できます。
class SampleItem
extend WithTax
attr_accessor :name, :price
attr_with_tax :price, rounding_method: :round, rate_type: :reduced
def initialize(name, price)
@name = name
@price = price
end
end
sample_item.price #=> 123
sample_item.price_with_tax #=> 133
attr_with_max
は複数の属性にも設定できます。
class SampleItem
extend WithTax
attr_accessor :name, :price, :price_takeout
attr_with_tax :price, rounding_method: :round
attr_with_tax :price_takeout, rounding_method: :round, rate_type: :reduced
def initialize(name, price, price_takeout)
@name = name
@price = price
@price_takeout = price_takeout
end
end
sample_item.price #=> 123
sample_item.price_with_tax #=> 135
sample_item.price_takeout #=> 123
sample_item.price_takeout_with_tax #=> 133
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.
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.
Bug reports and pull requests are welcome on GitHub at https://github.com/ken1flan/with_tax.
FAQs
Unknown package
We found that with_tax demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.