schapi 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/schapi/api.rb +89 -0
  3. data/schapi/domain.rb +11 -0
  4. metadata +66 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: '03686f5e48a138434877dee1123978663da13b54'
4
+ data.tar.gz: 957b7009b09996e5ee55090199611942abf7772a
5
+ SHA512:
6
+ metadata.gz: 531ca0f1b65b68065235d27c52370f970270146fc435a62cf1d50783027fb1d36a49ea0f01ad504e766e7a19aac56408ab1b440ac99c07f6436a9e7a6fa24a44
7
+ data.tar.gz: 667659aa80fda779475f83a3fbfd5f40fbc6b3ddb195247faaff5be9b38bf470906e2da4a425f45dad8bb65f3117591a9b349cd118cd53f6ee74fc9167463a91
data/schapi/api.rb ADDED
@@ -0,0 +1,89 @@
1
+ module Schapi
2
+ module Kind
3
+ KINDERGARTEN = 1
4
+ ELEMENTARY = 2
5
+ MIDDLE = 3
6
+ HIGH = 4
7
+ end
8
+
9
+ module Region
10
+ SEOUL = 'stu.sen.go.kr'
11
+ BUSAN = 'stu.pen.go.kr'
12
+ DAEGU = 'stu.dge.go.kr'
13
+ INCHEON = 'stu.ice.go.kr'
14
+ GWANGJU = 'stu.gen.go.kr'
15
+ DAEJEON = 'stu.dje.go.kr'
16
+ ULSAN = 'stu.use.go.kr'
17
+ SEJONG = 'stu.sje.go.kr'
18
+ GYEONGGI = 'stu.cbe.go.kr'
19
+ KANGWON = 'stu.kwe.go.kr'
20
+ CHUNGBUK = 'stu.cbe.go.kr'
21
+ CHUNGNAM = 'stu.cne.go.kr'
22
+ JEONBUK = 'stu.jbe.go.kr'
23
+ JEONNAM = 'stu.jne.go.kr'
24
+ GYEONGBUK = 'stu.gbe.go.kr'
25
+ GYEONGNAM = 'stu.gne.go.kr'
26
+ JEJU = 'stu.jje.go.kr'
27
+ end
28
+
29
+ module URL
30
+ MONTHLY_MENUS = 'http://%s/sts_sci_md00_001.do?schulCode=%s&schulCrseScCode=%d&schulCrseScScore=%02d&schYm=%d%02d'
31
+ end
32
+
33
+ class SchoolAPI
34
+ require 'nokogiri'
35
+ require 'open-uri'
36
+ require File.dirname(__FILE__) + '/domain'
37
+
38
+ def initialize(kind, region, code)
39
+ @kind = kind
40
+ @region = region
41
+ @code = code
42
+ end
43
+
44
+ def get_monthly_menus_url(year, month)
45
+ return URL::MONTHLY_MENUS % [@region, @code, @kind, @kind, year, month]
46
+ end
47
+
48
+ def get_menu_hash_from_data(data)
49
+ menu = Hash.new
50
+ chunks = data.scan(/[가-힣]+\([가-힣]+\)|[가-힣]+/)
51
+
52
+ timings = ['조식', '중식', '석식']
53
+ timing = 0
54
+
55
+ chunks.each do |t|
56
+ if t.match /[조중석]식/
57
+ timing = timings.index(t)
58
+ menu[timing] = Array.new
59
+ else
60
+ menu[timing].push(t)
61
+ end
62
+ end
63
+
64
+ return menu
65
+ end
66
+
67
+ def get_monthly_menus_from_doc(doc)
68
+ menus = Hash.new
69
+
70
+ doc.css('.tbl_calendar.tbl_type3 td').select{ |e| e.text != ' ' }.each.with_index do |e, i|
71
+ menus[i + 1] = self.get_menu_hash_from_data(e.text)
72
+ end
73
+
74
+ return menus
75
+ end
76
+
77
+ def get_monthly_menus(year, month)
78
+ menus = Hash.new
79
+ doc = Nokogiri::HTML open(self.get_monthly_menus_url(year, month))
80
+
81
+ self.get_monthly_menus_from_doc(doc).each_pair do |d, m|
82
+ breakfast, lunch, dinner = m[0], m[1], m[2]
83
+ menus[d] = Menu.new breakfast, lunch, dinner
84
+ end
85
+
86
+ return menus
87
+ end
88
+ end
89
+ end
data/schapi/domain.rb ADDED
@@ -0,0 +1,11 @@
1
+ module Schapi
2
+ class Menu
3
+ attr_accessor :breakfast, :lunch, :dinner
4
+
5
+ def initialize(breakfast, lunch, dinner)
6
+ @breakfast = breakfast
7
+ @lunch = lunch
8
+ @dinner = dinner
9
+ end
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: schapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Toygrammer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.0
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.8.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 1.8.0
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.8.2
33
+ description: School API for Ruby
34
+ email: gdh0608@naver.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - schapi/api.rb
40
+ - schapi/domain.rb
41
+ homepage: ''
42
+ licenses:
43
+ - Apache-2.0
44
+ metadata:
45
+ source_code_uri: https://github.com/DSM-SchoolAPI/Schapi-RB
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.6.11
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Schapi for Ruby
66
+ test_files: []