lib/sfc-room/parse.rb in sfc-room-0.0.1 vs lib/sfc-room/parse.rb in sfc-room-0.1.0
- old
+ new
@@ -1,20 +1,28 @@
#coding:utf-8
module SFCRoom
+ class ParseError < StandardError
+ end
- def parse(str)
+ def parse(source_str)
building = nil
- q = Utils.convert_for_search(str)
+ q = Utils.convert_for_search(source_str)
SFCRoom::Buildings::List.each do |b|
arr = [b.to_s]
arr.push SFCRoom::Buildings::JapaneseName[b]
arr.push SFCRoom::Buildings::RomanChar[b]
arr.push SFCRoom::Buildings::GreekChar[b]
arr += SFCRoom::Buildings::Aliases[b]
arr.delete(nil)
arr.each do |word|
- if q.match(/^#{Utils.convert_for_search word}/)
+ search_word = Utils.convert_for_search word
+ if search_word.length == 1
+ if q.match(/^#{search_word}[SN]?\d*$/i)
+ building = b
+ break
+ end
+ elsif q.match(/^#{search_word}/i)
building = b
break
end
end
break if building
@@ -48,11 +56,12 @@
end
elsif m = q.match(/(\d+)/)
number = m[1]
floor = m[1][0,1]
end
+ raise ParseError unless building
- return Room.new building,number,floor
+ return Room.new(:building => building, :room => number, :floor => floor, :source => source_str)
end
module_function :parse
end