Skip to content

Instantly share code, notes, and snippets.

@284km
Created July 9, 2015 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 284km/ec740c74a47321ed309c to your computer and use it in GitHub Desktop.
Save 284km/ec740c74a47321ed309c to your computer and use it in GitHub Desktop.
require 'minitest/autorun'
def split_price(price_text)
price_text.to_s.match(/([^万円]*)(.*)/)[1..2]
end
describe 'split_price' do
let(:manyen) { '110.0万円'}
let(:yen) { '2015円'}
let(:comma) { '1,123,456円'}
let(:hyphen) { '110 - 120万円'}
let(:zenkaku) { '2015円'}
let(:jponly) { '価格未定'}
let(:blank) { nil }
it { split_price(manyen).must_equal ['110.0', '万円'] }
it { split_price(yen).must_equal ['2015', '円'] }
it { split_price(comma).must_equal ['1,123,456', '円'] }
it { split_price(hyphen).must_equal ['110 - 120', '万円'] }
it { split_price(zenkaku).must_equal ['2015', '円'] }
it { split_price(jponly).must_equal ['価格未定', ''] }
it { split_price(blank).must_equal ['', ''] }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment