sfc-room 0.0.1 → 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6516d72b0f8e2d9aaaab00e77cf7bc0625c9193e
4
+ data.tar.gz: 64dc23da8baca5685400575aa88081d6f2891f70
5
+ SHA512:
6
+ metadata.gz: 2c3cdb043be7c46fe199bc1c38d8809601cbedc94aa4d08620449862287ab57a42a684e01e0f897ed0fffd8d78333ff59c8db46925362da1bfaa5f48225b0c9f
7
+ data.tar.gz: 0a145a1b42835ce709a5f8d999cfb6dfcf2a22dd05d955dc171e4c49c810b0e2aabeb1b36eeceecfb7a603b895f9b4e57890e14da35f7261897f961b42e8c3b7
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  .*.swp
6
+ .ruby-version
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.0.0
5
+ - 1.9.3
6
+ - 1.9.2
7
+
data/README.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  SFCRoom is a parser for clasrooms of Keio University Shonan Fujisawa Campus.
4
4
 
5
+ - https://github.com/ymrl/sfc-room
6
+ - http://rubygems.org/gems/sfc-room
7
+ - [![Build Status](https://travis-ci.org/ymrl/sfc-room.svg?branch=master)](https://travis-ci.org/ymrl/sfc-room)
8
+
9
+
5
10
  ## Installation
6
11
 
7
12
  Add this line to your application's Gemfile:
@@ -36,3 +41,27 @@ Or install it yourself as:
36
41
  3. Commit your changes (`git commit -am 'Added some feature'`)
37
42
  4. Push to the branch (`git push origin my-new-feature`)
38
43
  5. Create new Pull Request
44
+
45
+ ## LICENSE
46
+
47
+ The MIT License (MIT)
48
+
49
+ Copyright (c) 2012 ymrl
50
+
51
+ Permission is hereby granted, free of charge, to any person obtaining a copy
52
+ of this software and associated documentation files (the "Software"), to deal
53
+ in the Software without restriction, including without limitation the rights
54
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
55
+ copies of the Software, and to permit persons to whom the Software is
56
+ furnished to do so, subject to the following conditions:
57
+
58
+ The above copyright notice and this permission notice shall be included in
59
+ all copies or substantial portions of the Software.
60
+
61
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
62
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
63
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
64
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
65
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
66
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
67
+ THE SOFTWARE.
@@ -162,10 +162,10 @@ module SFCRoom
162
162
  N2 = "n2"
163
163
  S1 = "s1"
164
164
  S2 = "s2"
165
- IIJHouse = 1
166
- DocomoHouse = 2
167
- DNPHouse = 3
168
- TateuchiHouse = 4
169
- MoriAtelier = 5
165
+ IIJHouse = "1"
166
+ DocomoHouse = "2"
167
+ DNPHouse = "3"
168
+ TateuchiHouse = "4"
169
+ MoriAtelier = "5"
170
170
  end
171
171
  end
@@ -1,9 +1,11 @@
1
1
  #coding:utf-8
2
2
  module SFCRoom
3
+ class ParseError < StandardError
4
+ end
3
5
 
4
- def parse(str)
6
+ def parse(source_str)
5
7
  building = nil
6
- q = Utils.convert_for_search(str)
8
+ q = Utils.convert_for_search(source_str)
7
9
  SFCRoom::Buildings::List.each do |b|
8
10
  arr = [b.to_s]
9
11
  arr.push SFCRoom::Buildings::JapaneseName[b]
@@ -12,7 +14,13 @@ module SFCRoom
12
14
  arr += SFCRoom::Buildings::Aliases[b]
13
15
  arr.delete(nil)
14
16
  arr.each do |word|
15
- if q.match(/^#{Utils.convert_for_search word}/)
17
+ search_word = Utils.convert_for_search word
18
+ if search_word.length == 1
19
+ if q.match(/^#{search_word}[SN]?\d*$/i)
20
+ building = b
21
+ break
22
+ end
23
+ elsif q.match(/^#{search_word}/i)
16
24
  building = b
17
25
  break
18
26
  end
@@ -50,8 +58,9 @@ module SFCRoom
50
58
  number = m[1]
51
59
  floor = m[1][0,1]
52
60
  end
61
+ raise ParseError unless building
53
62
 
54
- return Room.new building,number,floor
63
+ return Room.new(:building => building, :room => number, :floor => floor, :source => source_str)
55
64
  end
56
65
  module_function :parse
57
66
  end
@@ -1,8 +1,13 @@
1
1
  class SFCRoom::Room
2
- def initialize building,room,floor=nil
3
- @building = building
4
- @room = room
5
- @floor = floor
2
+ def initialize(opts={})
3
+ {:building => nil, :room => nil, :floor => nil, :source => nil}.each do |k,v|
4
+ opts[k] = v unless opts.has_key? k
5
+ end
6
+ raise ArgumentError, "building must be String" unless opts[:building]
7
+ @building = opts[:building]
8
+ @room = opts[:room]
9
+ @floor = opts[:floor]
10
+ @source = opts[:source]
6
11
  end
7
12
  def inspect
8
13
  "[SFCRoom #{to_roman}]"
@@ -31,5 +36,5 @@ class SFCRoom::Room
31
36
  def building_number_for_sfs
32
37
  SFCRoom::Buildings::SFSNumber[@building] || SFCRoom::Buildings::SFSNumber[SFCRoom::Buildings::Others]
33
38
  end
34
- attr_reader :building,:floor,:room
39
+ attr_reader :building,:floor,:room,:source
35
40
  end
@@ -1,16 +1,19 @@
1
1
  #coding:UTF-8
2
2
  require 'nkf'
3
- require 'jcode' if RUBY_VERSION < "1.9"
4
3
 
5
4
  module SFCRoom::Utils
6
5
  def self.greek_downcase str
7
- str.tr('Α-Ω','α-ω')
6
+ encoding = str.encoding
7
+ return str.encode(Encoding::UTF_8).tr('Α-Ω','α-ω').encode(encoding)
8
8
  end
9
9
  def self.greek_upcase str
10
+ encoding = str.encoding
11
+ return str.encode(Encoding::UTF_8).tr('α-ω','Α-Ω').encode(encoding)
10
12
  str.tr('α-ω','Α-Ω')
11
13
  end
12
14
  def self.hankaku_zenkaku str
13
- NKF::nkf('-Z1 -Ww',str)
15
+ encoding = str.encoding
16
+ return NKF::nkf('-Z1 -Ww',str).encode(encoding)
14
17
  end
15
18
 
16
19
  def self.convert_for_search str
@@ -1,3 +1,3 @@
1
1
  module SFCRoom
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -7,9 +7,11 @@ Gem::Specification.new do |s|
7
7
  s.version = SFCRoom::VERSION
8
8
  s.authors = ["ymrl"]
9
9
  s.email = ["ymrl@ymrl.net"]
10
- s.homepage = ""
10
+ s.homepage = "https://github.com/ymrl/sfc-room"
11
11
  s.summary = %q{Parser for SFC classrooms}
12
- s.description = %q{Parser for SFC classrooms}
12
+ s.description = %q{SFCRoom is a parser for clasrooms of Keio University Shonan Fujisawa Campus. }
13
+ s.licenses = ['MIT']
14
+ s.required_ruby_version = ">= 1.9"
13
15
 
14
16
  s.rubyforge_project = "sfc-room"
15
17
 
@@ -19,6 +21,8 @@ Gem::Specification.new do |s|
19
21
  s.require_paths = ["lib"]
20
22
 
21
23
  # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
24
+ s.add_development_dependency "rspec"
25
+ s.add_development_dependency "rake"
26
+ s.add_development_dependency "bundler", "~> 1.3"
23
27
  # s.add_runtime_dependency "rest-client"
24
28
  end
@@ -3,12 +3,17 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
3
3
 
4
4
  describe SFCRoom do
5
5
  describe 'parser' do
6
+ it 'raises ParseError' do
7
+ expect{SFCRoom::parse('')}.to raise_error(SFCRoom::ParseError)
8
+ end
9
+
6
10
  it 'can parse all roman classroom' do
7
11
  include SFCRoom
8
12
  room = SFCRoom.parse('i11')
9
13
  room.building.should eql(SFCRoom::Buildings::Iota)
10
14
  room.room.should eql('11')
11
15
  room.floor.should eql('1')
16
+ room.source.should eql('i11')
12
17
  end
13
18
  it 'can parse greek classroom' do
14
19
  include SFCRoom
@@ -17,6 +22,7 @@ describe SFCRoom do
17
22
  room.room.should eql('411')
18
23
  room.floor.should eql('4')
19
24
  room.to_s.should eql('イオタ411')
25
+ room.source.should eql('ι411')
20
26
  end
21
27
 
22
28
  it 'can parse japanese classroom' do
@@ -25,14 +31,16 @@ describe SFCRoom do
25
31
  room.room.should eql('19')
26
32
  room.floor.should eql('1')
27
33
  room.to_s.should eql('ラムダ19')
34
+ room.source.should eql('ラムダ19')
28
35
  end
29
-
36
+
30
37
  it 'can parse delta classroom' do
31
38
  room = SFCRoom.parse('ΔS113')
32
39
  room.building.should eql(SFCRoom::Buildings::Delta)
33
40
  room.room.should eql('S113')
34
41
  room.floor.should eql('s1')
35
42
  room.to_s.should eql('デルタS113')
43
+ room.source.should eql('ΔS113')
36
44
  end
37
45
 
38
46
  it 'can parse tau loft' do
@@ -41,6 +49,15 @@ describe SFCRoom do
41
49
  room.room.should eql('20')
42
50
  room.floor.should eql('2')
43
51
  room.to_s.should eql('タウ20')
52
+ room.source.should eql('タウ館2階ロフト')
53
+ end
54
+
55
+ it 'can parse IIJHouse' do
56
+ room = SFCRoom.parse('IIJハウス')
57
+ room.building.should eql(SFCRoom::Buildings::Nu)
58
+ room.floor.should eql('1')
59
+ room.to_s.should eql('ニュー')
60
+ room.source.should eql('IIJハウス')
44
61
  end
45
62
 
46
63
 
@@ -0,0 +1,55 @@
1
+ #coding:utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper.rb'
3
+
4
+ describe SFCRoom do
5
+ describe SFCRoom::Room do
6
+ let :building do
7
+ SFCRoom::Buildings::Tau
8
+ end
9
+
10
+ let :room do
11
+ "20"
12
+ end
13
+
14
+ let :floor do
15
+ '2'
16
+ end
17
+
18
+ let :source do
19
+ 'タウ館2階ロフト'
20
+ end
21
+
22
+ context 'initialize' do
23
+ it 'can be initialized with building' do
24
+ room = SFCRoom::Room.new(building: building)
25
+ expect(room).to be_instance_of SFCRoom::Room
26
+ end
27
+
28
+ it 'can not be initialized without building' do
29
+ expect{ SFCRoom::Room.new }.to raise_error(ArgumentError)
30
+ end
31
+ end
32
+
33
+ context 'instance' do
34
+ let :instance do
35
+ SFCRoom::Room.new(building: building, room: room, floor: floor, source: source)
36
+ end
37
+
38
+ it 'has room' do
39
+ expect(instance.room).to eq room
40
+ end
41
+
42
+ it 'has building' do
43
+ expect(instance.building).to eq building
44
+ end
45
+
46
+ it 'has floor' do
47
+ expect(instance.floor).to eq floor
48
+ end
49
+
50
+ it 'has source' do
51
+ expect(instance.source).to eq source
52
+ end
53
+ end
54
+ end
55
+ end
@@ -2,11 +2,6 @@
2
2
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
3
  $:.unshift File.expand_path(File.join(File.dirname(__FILE__)))
4
4
 
5
- if RUBY_VERSION < "1.9"
6
- $KCODE="UTF-8"
7
- end
8
-
9
-
10
5
  require 'sfc-room'
11
6
 
12
7
  #Dir[File.join(File.dirname(__FILE__), "..", "lib", "models", "**/*.rb")].each do |f|
@@ -1,5 +1,6 @@
1
1
  #coding:utf-8
2
2
  require File.dirname(__FILE__) + '/spec_helper.rb'
3
+ require 'kconv'
3
4
  describe SFCRoom do
4
5
  include SFCRoom::Utils
5
6
  describe 'Utils' do
@@ -14,6 +15,14 @@ describe SFCRoom do
14
15
  str = SFCRoom::Utils.greek_downcase(up)
15
16
  str.should eql(down)
16
17
  end
18
+ it 'can convert not UTF-8 string' do
19
+ str = SFCRoom::Utils.greek_upcase(Kconv.tosjis(down))
20
+ str.should eql(Kconv.tosjis(up))
21
+ str = SFCRoom::Utils.greek_downcase(Kconv.tosjis(up))
22
+ str.should eql(Kconv.tosjis(down))
23
+ end
24
+
25
+
17
26
  it 'not effect to other characters' do
18
27
  str = SFCRoom::Utils.greek_downcase(other)
19
28
  str.should eql(other)
metadata CHANGED
@@ -1,17 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sfc-room
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - ymrl
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-10-23 00:00:00.000000000 Z
13
- dependencies: []
14
- description: Parser for SFC classrooms
11
+ date: 2014-04-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ description: 'SFCRoom is a parser for clasrooms of Keio University Shonan Fujisawa
56
+ Campus. '
15
57
  email:
16
58
  - ymrl@ymrl.net
17
59
  executables: []
@@ -19,6 +61,7 @@ extensions: []
19
61
  extra_rdoc_files: []
20
62
  files:
21
63
  - .gitignore
64
+ - .travis.yml
22
65
  - Gemfile
23
66
  - README.md
24
67
  - Rakefile
@@ -30,33 +73,36 @@ files:
30
73
  - lib/sfc-room/version.rb
31
74
  - sfc-room.gemspec
32
75
  - spec/parser_spec.rb
76
+ - spec/room_spec.rb
33
77
  - spec/spec_helper.rb
34
78
  - spec/utils_spec.rb
35
- homepage: ''
36
- licenses: []
79
+ homepage: https://github.com/ymrl/sfc-room
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
37
83
  post_install_message:
38
84
  rdoc_options: []
39
85
  require_paths:
40
86
  - lib
41
87
  required_ruby_version: !ruby/object:Gem::Requirement
42
- none: false
43
88
  requirements:
44
- - - ! '>='
89
+ - - '>='
45
90
  - !ruby/object:Gem::Version
46
- version: '0'
91
+ version: '1.9'
47
92
  required_rubygems_version: !ruby/object:Gem::Requirement
48
- none: false
49
93
  requirements:
50
- - - ! '>='
94
+ - - '>='
51
95
  - !ruby/object:Gem::Version
52
96
  version: '0'
53
97
  requirements: []
54
98
  rubyforge_project: sfc-room
55
- rubygems_version: 1.8.11
99
+ rubygems_version: 2.0.3
56
100
  signing_key:
57
- specification_version: 3
101
+ specification_version: 4
58
102
  summary: Parser for SFC classrooms
59
103
  test_files:
60
104
  - spec/parser_spec.rb
105
+ - spec/room_spec.rb
61
106
  - spec/spec_helper.rb
62
107
  - spec/utils_spec.rb
108
+ has_rdoc: