credit-card-sms-parser 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7e4149648b6e301f6e8aa239353fa906e6d407b9
4
+ data.tar.gz: 934b1c08e284403ab362fa7dc84a5e80a9ab0e43
5
+ SHA512:
6
+ metadata.gz: 85b423130ccf96dc704dd2a5c35d717b8527b23eb43c2fd782ecd26ecaed6769043ae1d43545c32f71a59751d65bf84cd240697b7c3e021e4efc8fcdf633ec69
7
+ data.tar.gz: f51a10e44b7d21c71f5f6e816e0775b23b07c14a58bbe517d6886060e3d2eedb6521b393e2b22782022b8db210147c38cb0a6b6a946d58c5a39d7a1c8ed01f56
@@ -0,0 +1,33 @@
1
+ .bundle
2
+ /log
3
+ *.iml
4
+ .rvmrc
5
+ rvm.env
6
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
7
+ #
8
+ # If you find yourself ignoring temporary files generated by your text editor
9
+ # or operating system, you probably want to add a global ignore instead:
10
+ # git config --global core.excludesfile '~/.gitignore_global'
11
+
12
+ /app/.DS_Store
13
+ # Ignore bundler config.
14
+ /.bundle
15
+
16
+ /out
17
+ tmp
18
+ .sass-cache
19
+ .ruby-version
20
+ .ruby-gemset
21
+ # Ignore the default SQLite database.
22
+
23
+ # Ignore all logfiles and tempfiles.
24
+ /log/*
25
+ !/log/.keep
26
+ /tmp
27
+
28
+
29
+ /*.iml
30
+ .idea
31
+
32
+ # Exclude CTags
33
+ /tags
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tms_client.gemspec
4
+ gemspec
5
+
6
+ gem 'bump'
7
+ gem 'geminabox'
8
+ gem 'rake'
9
+ gem 'minitest'
10
+ gem 'activesupport'
11
+ gem 'rltk'
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ credit-card-sms-parser (0.0.5)
5
+ rltk
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (4.2.1)
11
+ i18n (~> 0.7)
12
+ json (~> 1.7, >= 1.7.7)
13
+ minitest (~> 5.1)
14
+ thread_safe (~> 0.3, >= 0.3.4)
15
+ tzinfo (~> 1.1)
16
+ builder (3.2.2)
17
+ bump (0.5.1)
18
+ faraday (0.9.1)
19
+ multipart-post (>= 1.2, < 3)
20
+ ffi (1.9.8)
21
+ filigree (0.3.2)
22
+ geminabox (0.12.4)
23
+ builder
24
+ faraday
25
+ httpclient (>= 2.2.7)
26
+ nesty
27
+ sinatra (>= 1.2.7)
28
+ httpclient (2.6.0.1)
29
+ i18n (0.7.0)
30
+ json (1.8.2)
31
+ minitest (5.5.1)
32
+ multipart-post (2.0.0)
33
+ nesty (1.0.2)
34
+ rack (1.6.0)
35
+ rack-protection (1.5.3)
36
+ rack
37
+ rake (10.4.2)
38
+ rltk (3.0.0)
39
+ ffi (>= 1.0.0)
40
+ filigree (>= 0.2.0)
41
+ sinatra (1.4.5)
42
+ rack (~> 1.4)
43
+ rack-protection (~> 1.4)
44
+ tilt (~> 1.3, >= 1.3.4)
45
+ thread_safe (0.3.5)
46
+ tilt (1.4.1)
47
+ tzinfo (1.2.2)
48
+ thread_safe (~> 0.1)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ activesupport
55
+ bump
56
+ credit-card-sms-parser!
57
+ geminabox
58
+ minitest
59
+ rake
60
+ rltk
@@ -0,0 +1,2 @@
1
+ # credit-card-sms-parser
2
+ 신용카드 회사에서 보내주는 sms 문자열을 읽어서 `가게명`, `사용금액`, `누적사용금액` 정보들을 추출해줍니다.
@@ -0,0 +1,13 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'bump/tasks'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.test_files = FileList['test/test*.rb']
8
+ #t.pattern = "spec/*_spec.rb"
9
+ t.verbose = true
10
+ end
11
+
12
+ desc 'Run tests'
13
+ task :default => :test
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'credit-card-sms-parser'
7
+ gem.version = '0.0.5'
8
+ gem.licenses = %w(MIT)
9
+ gem.authors = %w(Hanson Benjamin)
10
+ gem.email = %w(jehokim@live.com)
11
+ gem.description = %q{credit-card-sms-parser}
12
+ gem.summary = %q{It parses all Korean credit card messages.}
13
+ gem.homepage = 'https://github.com/kakao/credit-card-sms-parser'
14
+ gem.metadata['allowed_push_host'] = 'https://rubygems.org'
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ['lib']
20
+
21
+ gem.add_runtime_dependency 'rltk'
22
+ end
@@ -0,0 +1,47 @@
1
+ require 'active_support/core_ext/object'
2
+ require 'rltk/lexer'
3
+
4
+ class String
5
+ def to_num
6
+ if self[0] == '-'
7
+ (self[0] + self[1..-1].gsub(/\D/, '')).to_i
8
+ else
9
+ self.gsub(/\D/, '').to_i
10
+ end
11
+ end
12
+ end
13
+
14
+ class KoreanCreditCardLexer < RLTK::Lexer
15
+ rule(/\[Web발신\]/) { |t| [:HEADER, t]}
16
+ rule(/\(Web발신\)/) { |t| [:HEADER, t]}
17
+ rule(/체크카드출금/) { |t| [:HEADER, t]}
18
+ rule(/[\p{Hangul}\*]{2,4}님/) { |t| [:USER_NAME, t]}
19
+ rule(/누적[\s:\-]?[\d,\-]+원/) { |t| [:MONEY_TOTAL, t.to_num] }
20
+ rule(/누적-[\d,\-]+원/) { |t| [:MONEY_TOTAL, t.to_num] }
21
+ rule(/[\d,\-]+원/) { |t| [:MONEY, t.to_num] }
22
+ rule(/\(주\)\p{Hangul}+/) {|t| [:SHOP, t[3..-1]]}
23
+ rule(/\p{Hangul}+\([\d\*]{4}\)/) {|t| [:CARD, t]}
24
+ rule(/\S+은행/) {|t| [:BANK, t]}
25
+ rule(/\S+카드/) {|t| [:CARD, t]}
26
+ rule(/\d\d\/\d\d/) {|t| [:DATE, t]}
27
+ rule(/\d\d:\d\d/) {|t| [:TIME, t]}
28
+ rule(/일시불/) { :TYPE }
29
+ rule(/주식회사\p{Hangul}+/) {|t| [:SHOP, t[4..-1]]}
30
+ rule(/\p{Hangul}+/) {|t| [:SHOP, t.strip]}
31
+ rule(/\//) {|t| [:SLASH, t]}
32
+ rule(/[\p{L}\p{P}]+/) {|t| [:WORD, t]}
33
+ rule(/[\d\*]+/) { :NUMBER }
34
+ rule(/\s/) {|t| [:SPACE, t]}
35
+ end
36
+
37
+ module CreditCardSmsParser
38
+ def parse_sms(phone_number, sms_message)
39
+ tokens = KoreanCreditCardLexer.lex(sms_message)
40
+ h = tokens.inject({}) do |memo, t|
41
+ memo[t.type] = t.value
42
+ memo
43
+ end
44
+
45
+ h.merge(card_name: phone_number)
46
+ end
47
+ end
@@ -0,0 +1,92 @@
1
+ require 'minitest/autorun'
2
+ require 'credit_card_sms_parser'
3
+ require 'active_support/core_ext/enumerable'
4
+
5
+ class TestCreditCardSmsParser < Minitest::Test
6
+ include CreditCardSmsParser
7
+ def setup
8
+ # @hyundae_card = CreditCardSmsParser::HyundaeCard.new
9
+ # @hana_card = CreditCardSmsParser::HanaCard.new
10
+ end
11
+
12
+ def test_parse
13
+ s = <<-eos
14
+ [Web발신]
15
+ [현대카드]-승인
16
+ 김재*님
17
+ 1,500원(일시불)
18
+ 마노핀익스프레스신림
19
+ 누적:354,220원
20
+ eos
21
+ puts "SHOP: #{parse_sms('111', s)[:SHOP]}"
22
+
23
+
24
+ s = <<-eos
25
+ [Web발신]
26
+ 하나(6*8*)김*호님 04/06 15:26 씨유판교 일시불/3,500원/누적-4,645원
27
+ eos
28
+
29
+ puts "SHOP: #{parse_sms('111', s)[:SHOP]}"
30
+
31
+ s = <<-eos
32
+ [Web발신]
33
+ KB국민카드 2*5*
34
+ 정*욱님
35
+ 03/25 09:30
36
+ 2,200원
37
+ 미니스톱판교점
38
+ 누적 97,440원
39
+ eos
40
+
41
+ puts "SHOP: #{parse_sms('111', s)[:SHOP]}"
42
+
43
+ s = <<-eos
44
+ [Web발신]
45
+ 삼성가족카드승인9785
46
+ 03/24 18:45
47
+ 10,000원
48
+ 일시불
49
+ 소문난우동
50
+ eos
51
+
52
+ puts "SHOP: #{parse_sms('111', s)[:SHOP]}"
53
+
54
+ s = <<-eos
55
+ [Web발신]
56
+ "KEB하나 박솔*님 4*6*
57
+ 일시불 30,000원
58
+ (주)이니 03/23 09:58
59
+ 누적 2,368,397원"
60
+ eos
61
+
62
+ puts "SHOP: #{parse_sms('111', s)[:SHOP]}"
63
+
64
+ s = <<-eos
65
+ [체크.승인]
66
+ 22,000원
67
+ 씨티BC(1*9*)김*정님
68
+ 01/23 12:34
69
+ 매일식당
70
+ eos
71
+
72
+ puts "SHOP: #{parse_sms('111', s)[:SHOP]}"
73
+
74
+ s = <<-eos
75
+ [Web발신]
76
+ [KB]04/08 21:27
77
+ 078501**554
78
+ 주식회사개성
79
+ 체크카드출금
80
+ 13,000
81
+ eos
82
+
83
+ puts "SHOP: #{parse_sms('111', s)[:SHOP]}"
84
+
85
+ s = <<-eos
86
+ [Web발신]
87
+ 하나(6*8*)김*호님 04/02 19:59 (주)보나 일시불/4,500원/누적-134,049원
88
+ eos
89
+
90
+ puts "SHOP: #{parse_sms('111', s)[:SHOP]}"
91
+ end
92
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: credit-card-sms-parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Hanson
8
+ - Benjamin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-04-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rltk
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description: credit-card-sms-parser
29
+ email:
30
+ - jehokim@live.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - README.md
39
+ - Rakefile
40
+ - credit-card-sms-parser.gemspec
41
+ - credit-card-sms-parser.iml
42
+ - lib/credit_card_sms_parser.rb
43
+ - test/test_credit_card_sms_parser.rb
44
+ homepage: https://github.com/kakao/credit-card-sms-parser
45
+ licenses:
46
+ - MIT
47
+ metadata:
48
+ allowed_push_host: https://rubygems.org
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 2.4.6
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: It parses all Korean credit card messages.
69
+ test_files:
70
+ - test/test_credit_card_sms_parser.rb