sfc-room 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.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .*.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sfcroom.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # SFCRoom
2
+
3
+ SFCRoom is a parser for clasrooms of Keio University Shonan Fujisawa Campus.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sfc-room'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sfc-room
18
+
19
+ ## Usage
20
+
21
+ require 'sfc-room'
22
+
23
+ room = SFCRoom.parse('イオタ411')
24
+ # Try with "i411","Ι411",...
25
+ # You can use also familliar names such as "サブウェイ","本館","情報基盤センター",...
26
+
27
+ room.to_greek #=> 'ι411'
28
+ room.to_japanese #=> 'イオタ411'
29
+ room.to_roman #=> 'i411'
30
+
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new do |spec|
5
+ spec.pattern = 'spec/**/*_spec.rb'
6
+ spec.rspec_opts = ['--backtrace']
7
+ end
8
+
9
+ task :default => :spec
@@ -0,0 +1,171 @@
1
+ #coding:UTF-8
2
+ module SFCRoom
3
+ module Buildings
4
+ Alpha = :alpha
5
+ Omega = :omega
6
+ Mu = :mu
7
+ Kappa = :kappa
8
+ Epsilon = :epsilon
9
+ Iota = :iota
10
+ Omicron = :omicron
11
+ Lambda = :lambda
12
+ Theta = :theta
13
+ Delta = :delta
14
+ Tau = :tau
15
+ Psi = :psi
16
+ Phi = :phi
17
+ Gamma = :gamma
18
+ Sigma = :sigma
19
+ Nu = :nu
20
+ Zeta = :zeta
21
+ Xi = :xi
22
+ Eta = :eta
23
+ Lounge = :lounge
24
+ GuestHouse = :guest_house
25
+ Others = :others
26
+
27
+ List = [
28
+ Alpha,
29
+ Omega,
30
+ Mu,
31
+ Kappa,
32
+ Epsilon,
33
+ Iota,
34
+ Omicron,
35
+ Lambda,
36
+ Theta,
37
+ Delta,
38
+ Tau,
39
+ Psi,
40
+ Phi,
41
+ Gamma,
42
+ Sigma,
43
+ Nu,
44
+ Zeta,
45
+ Xi,
46
+ Eta,
47
+ Lounge,
48
+ ]
49
+ JapaneseName = {
50
+ Alpha => 'アルファ',
51
+ Omega => 'オメガ',
52
+ Mu => 'ミュー',
53
+ Kappa => 'カッパ',
54
+ Epsilon => 'イプシロン',
55
+ Iota => 'イオタ',
56
+ Omicron => 'オミクロン',
57
+ Lambda => 'ラムダ',
58
+ Theta => 'シータ',
59
+ Delta => 'デルタ',
60
+ Tau => 'タウ',
61
+ Psi => 'サイ',
62
+ Phi => 'フィー',
63
+ Gamma => 'ガンマ',
64
+ Sigma => 'シグマ',
65
+ Nu => 'ニュー',
66
+ Zeta => 'ゼータ',
67
+ Xi => 'グザイ',
68
+ Eta => 'イータ',
69
+ Lounge => '学生ラウンジ',
70
+ GuestHouse => 'セミナーゲストハウス',
71
+ Others => 'その他',
72
+ }
73
+ RomanChar = {
74
+ Alpha => 'A',
75
+ #Omega => '',
76
+ Mu => 'M',
77
+ Kappa => 'k',
78
+ Epsilon => 'e',
79
+ Iota => 'i',
80
+ Omicron => 'o',
81
+ Lambda => 'l',
82
+ #Theta => '',
83
+ #Delta => '',
84
+ Tau => 't',
85
+ #Psi => '',
86
+ #Phi => '',
87
+ #Gamma => '',
88
+ #Sigma => '',
89
+ #Nu => '',
90
+ Zeta => 'Z',
91
+ #Xi => '',
92
+ #Eta => '',
93
+ #Lounge => '',
94
+ #GuestHouse => '',
95
+ #Others => '',
96
+ }
97
+ GreekChar = {
98
+ Alpha => 'Α',
99
+ Omega => 'Ω',
100
+ Mu => 'Μ',
101
+ Kappa => 'κ',
102
+ Epsilon => 'ε',
103
+ Iota => 'ι',
104
+ Omicron => 'ο',
105
+ Lambda => 'λ',
106
+ Theta => 'θ',
107
+ Delta => 'Δ',
108
+ Tau => 'τ',
109
+ Psi => 'Ψ',
110
+ Phi => 'Φ',
111
+ Gamma => 'Γ',
112
+ Sigma => 'Σ',
113
+ Nu => 'Ν',
114
+ Zeta => 'Ζ',
115
+ Xi => 'ξ',
116
+ Eta => 'η',
117
+ #Lounge => '',
118
+ #GuestHouse => '',
119
+ #Others => '',
120
+ }
121
+ Aliases = {
122
+ Alpha => %w|本館 事務|,
123
+ Omega => %w||,
124
+ Mu => %w|メディア|,
125
+ Kappa => %w||,
126
+ Epsilon => %w||,
127
+ Iota => %w||,
128
+ Omicron => %w||,
129
+ Lambda => %w||,
130
+ Theta => %w|講堂|,
131
+ Delta => %w||,
132
+ Tau => %w|院棟 大学院棟 ロフト|,
133
+ Psi => %w||,
134
+ Phi => %w||,
135
+ Gamma => %w|体育館 アリーナ|,
136
+ Sigma => %w|生協 タブリエ レディバード|,
137
+ Nu => %w|Docomoハウス ドコモハウス DNPハウス 舘内ハウス 森アトリエ IIJハウス デザインスタジオ|,
138
+ Zeta => %w|情報基盤センター|,
139
+ Xi => %w|ものづくり工房|,
140
+ Eta => %w||,
141
+ Lounge => %w|サブウェイ|,
142
+ GuestHouse => %w|ゲストハウス|,
143
+ Others => %w||,
144
+ }
145
+ SFSNumber = {
146
+ Kappa => "1",
147
+ Epsilon => "2",
148
+ Iota => "3",
149
+ Omicron => "4",
150
+ Lambda => "5",
151
+ Delta => "6",
152
+ Tau => "7",
153
+ Zeta => "8",
154
+ Nu => "9",
155
+ Omega => "10",
156
+ Others => "11",
157
+ }
158
+ end
159
+
160
+ module Floors
161
+ N1 = "n1"
162
+ N2 = "n2"
163
+ S1 = "s1"
164
+ S2 = "s2"
165
+ IIJHouse = 1
166
+ DocomoHouse = 2
167
+ DNPHouse = 3
168
+ TateuchiHouse = 4
169
+ MoriAtelier = 5
170
+ end
171
+ end
@@ -0,0 +1,58 @@
1
+ #coding:utf-8
2
+ module SFCRoom
3
+
4
+ def parse(str)
5
+ building = nil
6
+ q = Utils.convert_for_search(str)
7
+ SFCRoom::Buildings::List.each do |b|
8
+ arr = [b.to_s]
9
+ arr.push SFCRoom::Buildings::JapaneseName[b]
10
+ arr.push SFCRoom::Buildings::RomanChar[b]
11
+ arr.push SFCRoom::Buildings::GreekChar[b]
12
+ arr += SFCRoom::Buildings::Aliases[b]
13
+ arr.delete(nil)
14
+ arr.each do |word|
15
+ if q.match(/^#{Utils.convert_for_search word}/)
16
+ building = b
17
+ break
18
+ end
19
+ end
20
+ break if building
21
+ end
22
+ number = nil
23
+ floor = nil
24
+ if building == SFCRoom::Buildings::Delta
25
+ if m = q.match(/([ns])(\d+)/)
26
+ number = "#{m[1]}#{m[2]}".upcase
27
+ floor = "#{m[1]}#{m[2][0,1]}"
28
+ end
29
+ elsif building == SFCRoom::Buildings::Tau && m = q.match(/([23][f階])?(ロフト|loft)/)
30
+ if m[1]
31
+ number = "#{m[1][0,1]}0"
32
+ floor = m[1][0,1]
33
+ else
34
+ number = "20"
35
+ floor = "2"
36
+ end
37
+ elsif building == SFCRoom::Buildings::Nu && m = q.match(/iij|docomo|ドコモ|舘内|森|dnp/i)
38
+ if q.match(/iij/i)
39
+ floor = SFCRoom::Floors::IIJHouse
40
+ elsif q.match(/docomo|ドコモ/i)
41
+ floor = SFCRoom::Floors::DocomoHouse
42
+ elsif q.match(/dnp/i)
43
+ floor = SFCRoom::Floors::DNPHouse
44
+ elsif q.match(/舘内/i)
45
+ floor = SFCRoom::Floors::TateuchiHouse
46
+ elsif q.match(/森/i)
47
+ floor = SFCRoom::Floors::MoriAtelier
48
+ end
49
+ elsif m = q.match(/(\d+)/)
50
+ number = m[1]
51
+ floor = m[1][0,1]
52
+ end
53
+
54
+ return Room.new building,number,floor
55
+ end
56
+ module_function :parse
57
+ end
58
+
@@ -0,0 +1,35 @@
1
+ class SFCRoom::Room
2
+ def initialize building,room,floor=nil
3
+ @building = building
4
+ @room = room
5
+ @floor = floor
6
+ end
7
+ def inspect
8
+ "[SFCRoom #{to_roman}]"
9
+ end
10
+ def to_s
11
+ to_japanese
12
+ end
13
+ def to_greek
14
+ "#{building_in_greek}#{@room}"
15
+ end
16
+ def to_roman
17
+ "#{building_in_roman}#{@room}"
18
+ end
19
+ def to_japanese
20
+ "#{building_in_japanese}#{@room}"
21
+ end
22
+ def building_in_japanese
23
+ SFCRoom::Buildings::JapaneseName[@building]
24
+ end
25
+ def building_in_greek
26
+ SFCRoom::Buildings::GreekChar[@building] || SFCRoom::Buildings::JapaneseName[@building]
27
+ end
28
+ def building_in_roman
29
+ SFCRoom::Buildings::RomanChar[@building] || SFCRoom::Buildings::JapaneseName[@building]
30
+ end
31
+ def building_number_for_sfs
32
+ SFCRoom::Buildings::SFSNumber[@building] || SFCRoom::Buildings::SFSNumber[SFCRoom::Buildings::Others]
33
+ end
34
+ attr_reader :building,:floor,:room
35
+ end
@@ -0,0 +1,19 @@
1
+ #coding:UTF-8
2
+ require 'nkf'
3
+ require 'jcode' if RUBY_VERSION < "1.9"
4
+
5
+ module SFCRoom::Utils
6
+ def self.greek_downcase str
7
+ str.tr('Α-Ω','α-ω')
8
+ end
9
+ def self.greek_upcase str
10
+ str.tr('α-ω','Α-Ω')
11
+ end
12
+ def self.hankaku_zenkaku str
13
+ NKF::nkf('-Z1 -Ww',str)
14
+ end
15
+
16
+ def self.convert_for_search str
17
+ self.hankaku_zenkaku self.greek_downcase(str).downcase
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module SFCRoom
2
+ VERSION = "0.0.1"
3
+ end
data/lib/sfc-room.rb ADDED
@@ -0,0 +1,15 @@
1
+ #coding:utf-8
2
+ $:.unshift(File.dirname(__FILE__)) unless
3
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
4
+
5
+ directory = File.expand_path(File.dirname(__FILE__))
6
+
7
+ require directory + "/sfc-room/version.rb"
8
+ require directory + "/sfc-room/constants.rb"
9
+ require directory + "/sfc-room/utils.rb"
10
+ require directory + "/sfc-room/room.rb"
11
+ require directory + "/sfc-room/parse.rb"
12
+
13
+ module SFCRoom
14
+ # Your code goes here...
15
+ end
data/sfc-room.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sfc-room/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sfc-room"
7
+ s.version = SFCRoom::VERSION
8
+ s.authors = ["ymrl"]
9
+ s.email = ["ymrl@ymrl.net"]
10
+ s.homepage = ""
11
+ s.summary = %q{Parser for SFC classrooms}
12
+ s.description = %q{Parser for SFC classrooms}
13
+
14
+ s.rubyforge_project = "sfc-room"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
@@ -0,0 +1,48 @@
1
+ #coding:utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper.rb'
3
+
4
+ describe SFCRoom do
5
+ describe 'parser' do
6
+ it 'can parse all roman classroom' do
7
+ include SFCRoom
8
+ room = SFCRoom.parse('i11')
9
+ room.building.should eql(SFCRoom::Buildings::Iota)
10
+ room.room.should eql('11')
11
+ room.floor.should eql('1')
12
+ end
13
+ it 'can parse greek classroom' do
14
+ include SFCRoom
15
+ room = SFCRoom.parse('ι411')
16
+ room.building.should eql(SFCRoom::Buildings::Iota)
17
+ room.room.should eql('411')
18
+ room.floor.should eql('4')
19
+ room.to_s.should eql('イオタ411')
20
+ end
21
+
22
+ it 'can parse japanese classroom' do
23
+ room = SFCRoom.parse('ラムダ19')
24
+ room.building.should eql(SFCRoom::Buildings::Lambda)
25
+ room.room.should eql('19')
26
+ room.floor.should eql('1')
27
+ room.to_s.should eql('ラムダ19')
28
+ end
29
+
30
+ it 'can parse delta classroom' do
31
+ room = SFCRoom.parse('ΔS113')
32
+ room.building.should eql(SFCRoom::Buildings::Delta)
33
+ room.room.should eql('S113')
34
+ room.floor.should eql('s1')
35
+ room.to_s.should eql('デルタS113')
36
+ end
37
+
38
+ it 'can parse tau loft' do
39
+ room = SFCRoom.parse('タウ館2階ロフト')
40
+ room.building.should eql(SFCRoom::Buildings::Tau)
41
+ room.room.should eql('20')
42
+ room.floor.should eql('2')
43
+ room.to_s.should eql('タウ20')
44
+ end
45
+
46
+
47
+ end
48
+ end
@@ -0,0 +1,14 @@
1
+ #coding:utf-8
2
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__)))
4
+
5
+ if RUBY_VERSION < "1.9"
6
+ $KCODE="UTF-8"
7
+ end
8
+
9
+
10
+ require 'sfc-room'
11
+
12
+ #Dir[File.join(File.dirname(__FILE__), "..", "lib", "models", "**/*.rb")].each do |f|
13
+ # require f
14
+ #end
@@ -0,0 +1,29 @@
1
+ #coding:utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper.rb'
3
+ describe SFCRoom do
4
+ include SFCRoom::Utils
5
+ describe 'Utils' do
6
+ down = 'αβγδεζηθικλμνξοπρςστυφχψω'
7
+ up = 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡ΢ΣΤΥΦΧΨΩ'
8
+ other = 'hogehogeほげほげ'
9
+ it 'can convert downcase greek to upcase ' do
10
+ str = SFCRoom::Utils.greek_upcase(down)
11
+ str.should eql(up)
12
+ end
13
+ it 'can convert upcase greek to downcase ' do
14
+ str = SFCRoom::Utils.greek_downcase(up)
15
+ str.should eql(down)
16
+ end
17
+ it 'not effect to other characters' do
18
+ str = SFCRoom::Utils.greek_downcase(other)
19
+ str.should eql(other)
20
+ str = SFCRoom::Utils.greek_upcase(other)
21
+ str.should eql(other)
22
+ str = SFCRoom::Utils.greek_upcase(up)
23
+ str.should eql(up)
24
+ str = SFCRoom::Utils.greek_downcase(down)
25
+ str.should eql(down)
26
+ end
27
+ end
28
+ end
29
+
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sfc-room
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - ymrl
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Parser for SFC classrooms
15
+ email:
16
+ - ymrl@ymrl.net
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - README.md
24
+ - Rakefile
25
+ - lib/sfc-room.rb
26
+ - lib/sfc-room/constants.rb
27
+ - lib/sfc-room/parse.rb
28
+ - lib/sfc-room/room.rb
29
+ - lib/sfc-room/utils.rb
30
+ - lib/sfc-room/version.rb
31
+ - sfc-room.gemspec
32
+ - spec/parser_spec.rb
33
+ - spec/spec_helper.rb
34
+ - spec/utils_spec.rb
35
+ homepage: ''
36
+ licenses: []
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project: sfc-room
55
+ rubygems_version: 1.8.11
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Parser for SFC classrooms
59
+ test_files:
60
+ - spec/parser_spec.rb
61
+ - spec/spec_helper.rb
62
+ - spec/utils_spec.rb