Class: Schapi::SchoolAPI
- Inherits:
-
Object
- Object
- Schapi::SchoolAPI
- Defined in:
- lib/schapi/api.rb
Instance Method Summary collapse
- #get_menu_hash_from_data(data) ⇒ Object
- #get_monthly_menus(year, month) ⇒ Object
- #get_monthly_menus_from_doc(doc) ⇒ Object
- #get_monthly_menus_url(year, month) ⇒ Object
-
#initialize(kind, region, code) ⇒ SchoolAPI
constructor
A new instance of SchoolAPI.
Constructor Details
#initialize(kind, region, code) ⇒ SchoolAPI
Returns a new instance of SchoolAPI.
38 39 40 41 42 |
# File 'lib/schapi/api.rb', line 38 def initialize(kind, region, code) @kind = kind @region = region @code = code end |
Instance Method Details
#get_menu_hash_from_data(data) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/schapi/api.rb', line 48 def (data) = Hash.new chunks = data.scan(/[가-힣]+\([가-힣]+\)|[가-힣]+/) timings = ['조식', '중식', '석식'] timing = 0 chunks.each do |t| if t.match /[조중석]식/ timing = timings.index(t) [timing] = Array.new else [timing].push(t) end end return end |
#get_monthly_menus(year, month) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/schapi/api.rb', line 77 def (year, month) = Hash.new doc = Nokogiri::HTML open(self.(year, month)) self.(doc).each_pair do |d, m| breakfast, lunch, dinner = m[0], m[1], m[2] [d] = Menu.new breakfast, lunch, dinner end return end |
#get_monthly_menus_from_doc(doc) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/schapi/api.rb', line 67 def (doc) = Hash.new doc.css('.tbl_calendar.tbl_type3 td').select{ |e| e.text != ' ' }.each.with_index do |e, i| [i + 1] = self.(e.text) end return end |
#get_monthly_menus_url(year, month) ⇒ Object
44 45 46 |
# File 'lib/schapi/api.rb', line 44 def (year, month) return URL::MONTHLY_MENUS % [@region, @code, @kind, @kind, year, month] end |