uniform_invoice_lottery 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29c221b98f7a65111488e3762aaae586cbdd34a7
4
- data.tar.gz: 994775084bdb02197c5f1a22228a5c1c6e85a7f7
3
+ metadata.gz: e89798e7823c640221b8a2ac0b49d226164aad6a
4
+ data.tar.gz: f9c02a59ffe7973b2f74a77a00ce654e65d1de17
5
5
  SHA512:
6
- metadata.gz: 2312270fed9aa807ffc53bcbdc35b223fadede3e2376fb2c55bfc8bd6e86d216ae7cb4dde37b32e5a5f710817c18f610f72dadfbbeddf0bcb0c69cf29f2ce6fb
7
- data.tar.gz: 93cb94ebd48260d7dce4c11b12f0c4617c1bd09568ca3c5213dae0e8f4b29e693f19903d02530656358397ea93ce4e1d1d4a0dae595df4d8d912407584f27b78
6
+ metadata.gz: 7fdf534694afaef64454d4c19de3cb8024dea810f6b43cd4c08e2dcf9a8b071ce5591ee42e7726e7e12e2772783f98452852a3f0c57e3e5485fb12b52cda6763
7
+ data.tar.gz: 7b9018af7d2333a2d8ac038d27f7bb1d221abf6310df29c37f1572679732fc039309d8ab10cefa87cd4d0c2806543732bfefd881ee7e3675096aea6004526500
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ *.gem
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.2.0"
4
+ - "2.2.4"
5
+ script: bundle exec rspec
data/README.md CHANGED
@@ -20,38 +20,15 @@ Or install it yourself as:
20
20
  $ gem install uniform_invoice_lottery
21
21
 
22
22
  ## Usage
23
-
24
- 回傳號碼結果字串,例如:
25
23
  ```ruby
26
24
  require 'uniform_invoice_lottery'
27
- UniformInvoiceLottery.check '82930261', time: Time.new(2015, 7, 26)
28
- ```
29
-
30
- 嫌太長就這樣寫
25
+ prize = UniformInvoiceLottery.check '82930261', time: Time.new(2015, 7, 26)
26
+ prize = UniformInvoiceLottery.check '82930261', year: 2015, month: 7 day: 26
31
27
 
32
- ```ruby
33
- uni_invoice = UniformInvoiceLottery
34
- uni_invoice.check '82930261', time: Time.new(2015, 7, 26)
28
+ puts prize.amount # => "10000000"
29
+ puts prize.title # => "特別獎"
35
30
  ```
36
31
 
37
- 上面這段回傳 `"特別獎"`。
38
-
39
-
40
- 總共有這幾個回傳值:
41
-
42
- 特別獎
43
- 特獎
44
- 頭獎
45
- 二獎
46
- 三獎
47
- 四獎
48
- 五獎
49
- 六獎
50
- 增開六獎
51
- 下次再來,兩個月後又是一條好漢
52
-
53
- XD。
54
-
55
32
  ## Contributing
56
33
 
57
34
  1. Fork it ( https://github.com/Yukaii/uniform_invoice_lottery/fork )
@@ -14,5 +14,21 @@ module UniformInvoiceLottery
14
14
  def check invoice_code, opts={}
15
15
  LotteryCheckService.new.check(invoice_code, opts)
16
16
  end
17
+
18
+ def records
19
+ LotteryCrawler.crawler.records
20
+ end
21
+
22
+ def find_record_by(year: nil, start_month: nil)
23
+ record = LotteryCrawler.find_record_by(
24
+ year: year,
25
+ start_month: start_month,
26
+ end_month: start_month + 1
27
+ )
28
+
29
+ yield(record) if block_given?
30
+
31
+ record
32
+ end
17
33
  end
18
34
  end
@@ -11,6 +11,10 @@ module UniformInvoiceLottery
11
11
  def priority
12
12
  self.class.const_get(:PRIORITY)
13
13
  end
14
+
15
+ def to_s
16
+ "#{title}: NT$ #{amount}"
17
+ end
14
18
  end
15
19
 
16
20
  class SpecialPrize < Prize
@@ -68,7 +72,7 @@ module UniformInvoiceLottery
68
72
  end
69
73
 
70
74
  class NullPrize < Prize
71
- TITLE = "沒中"
75
+ TITLE = "沒中獎"
72
76
  AMOUNT = 0
73
77
  PRIORITY = 999
74
78
  end
@@ -1,3 +1,3 @@
1
1
  module UniformInvoiceLottery
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'uniform_invoice_lottery/support'
3
+ require 'uniform_invoice_lottery/exceptions'
4
+
5
+ describe UniformInvoiceLottery::Support do
6
+ before do
7
+ @object = Object.new
8
+ @object.extend(UniformInvoiceLottery::Support)
9
+ end
10
+
11
+ it "should calculate correct lottery month" do
12
+ expect( @object.get_draw_month( Time.new(2015, 1, 15) )).to eq(11)
13
+ expect( @object.get_draw_month( Time.new(2015, 1, 25) )).to eq( 1)
14
+ expect( @object.get_draw_month( Time.new(2015, 2, 28) )).to eq( 1)
15
+
16
+ expect( @object.get_lottery_months(3)).to eq([1,2])
17
+ expect( @object.get_lottery_months(1)).to eq([11,12])
18
+ # 奇數月開獎的說
19
+ expect{ @object.get_lottery_months(2) }.to raise_error(UniformInvoiceLottery::InvalidLotteryMonthError)
20
+ end
21
+ end
@@ -3,6 +3,47 @@ require 'uniform_invoice_lottery'
3
3
 
4
4
  describe UniformInvoiceLottery do
5
5
  it "can check lottery" do
6
- expect(UniformInvoiceLottery.check('82930261', time: Time.new(2015, 7, 26)).title).to eq("特別獎")
6
+ special_prize = UniformInvoiceLottery.check('82930261', time: Time.new(2015, 7, 26))
7
+ expect(special_prize.title).to eq("特別獎")
8
+ expect(special_prize.amount).to eq(10_000_000)
9
+ expect(special_prize.to_s).to eq("特別獎: NT$ 10000000")
10
+ end
11
+
12
+ it 'should load records' do
13
+ records = UniformInvoiceLottery.records
14
+
15
+ expect(records.class).to eq(Array)
16
+
17
+ unless records.empty?
18
+ expect(records.first.class).to eq(Hash)
19
+ %w(year start_month end_month special_prize grand_prize first_prizes additional_sixth_prizes).each {|k|
20
+ expect(records.first).to have_key(k)
21
+ }
22
+ end
23
+ end
24
+
25
+ it 'can find record by year and start_month' do
26
+ _r = {
27
+ 'year' => 104,
28
+ 'start_month' => 1,
29
+ 'end_month' => 2,
30
+ 'special_prize' => '60538935',
31
+ 'grand_prize' => '50887710',
32
+ 'first_prizes' => [
33
+ '63856949',
34
+ '39459262',
35
+ '61944942',
36
+ ],
37
+ 'additional_sixth_prizes' => [
38
+ '022',
39
+ '355',
40
+ '038',
41
+ ]
42
+ }
43
+ expect(UniformInvoiceLottery.find_record_by(year: 104, start_month: 1)).to eq(_r)
44
+
45
+ UniformInvoiceLottery.find_record_by(year: 104, start_month: 1) do |record|
46
+ expect(record).not_to be_nil
47
+ end
7
48
  end
8
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uniform_invoice_lottery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukai Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-17 00:00:00.000000000 Z
11
+ date: 2016-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -201,6 +201,7 @@ extra_rdoc_files: []
201
201
  files:
202
202
  - ".gitignore"
203
203
  - ".pryrc"
204
+ - ".travis.yml"
204
205
  - Gemfile
205
206
  - Guardfile
206
207
  - LICENSE.txt
@@ -214,8 +215,8 @@ files:
214
215
  - lib/uniform_invoice_lottery/prizes.rb
215
216
  - lib/uniform_invoice_lottery/support.rb
216
217
  - lib/uniform_invoice_lottery/version.rb
217
- - spec/data_crawler_spec.rb
218
218
  - spec/spec_helper.rb
219
+ - spec/support_spec.rb
219
220
  - spec/uniform_invoice_lottery_spec.rb
220
221
  - uniform_invoice_lottery.gemspec
221
222
  homepage: https://github.com/Yukaii/uniform-invoice-lottery
@@ -243,7 +244,7 @@ signing_key:
243
244
  specification_version: 4
244
245
  summary: "一個統一發票的查詢、兌獎 gem"
245
246
  test_files:
246
- - spec/data_crawler_spec.rb
247
247
  - spec/spec_helper.rb
248
+ - spec/support_spec.rb
248
249
  - spec/uniform_invoice_lottery_spec.rb
249
250
  has_rdoc:
@@ -1,36 +0,0 @@
1
- # require 'spec_helper'
2
- # require 'uniform_invoice_lottery'
3
-
4
- # describe UniformInvoiceLottery::DataCrawler do
5
-
6
- # let(:data_crawler) {
7
- # UniformInvoiceLottery::DataCrawler
8
- # }
9
-
10
- # describe "test DataCrawler module" do
11
- # it "should have DataCrawler sub module" do
12
- # records = data_crawler.records
13
-
14
- # expect(records.class).to eq(Array)
15
-
16
- # unless records.empty?
17
- # expect(records.first.class).to eq(Hash)
18
- # %w(year start_month end_month so_special_price special_price head_prices additional_sixth_prices).each {|k|
19
- # expect(records.first).to have_key(k)
20
- # }
21
- # end
22
- # end
23
-
24
- # it "should calculate correct lottery month" do
25
- # expect(data_crawler.get_draw_month( Time.new(2015, 1, 15) )).to eq(11)
26
- # expect(data_crawler.get_draw_month( Time.new(2015, 1, 25) )).to eq( 1)
27
- # expect(data_crawler.get_draw_month( Time.new(2015, 2, 28) )).to eq( 1)
28
-
29
- # expect(data_crawler.get_lottery_months(3)).to eq([1,2])
30
- # expect(data_crawler.get_lottery_months(1)).to eq([11,12])
31
- # # 奇數月開獎的說
32
- # expect{ data_crawler.get_lottery_months(2) }.to raise_error(UniformInvoiceLottery::InvalidLotteryMonthError)
33
- # end
34
- # end
35
-
36
- # end