Sha256: da665cae6d0ad492abc0fedcb190da6807578caf6acd2eb4954f1185d55e5899

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

#coding:utf-8
module SFCRoom

  def parse(str)
    building = nil
    q = Utils.convert_for_search(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}/)
          building = b
          break
        end
      end
      break if building
    end
    number = nil
    floor = nil
    if building == SFCRoom::Buildings::Delta
      if m = q.match(/([ns])(\d+)/)
        number = "#{m[1]}#{m[2]}".upcase
        floor = "#{m[1]}#{m[2][0,1]}"
      end
    elsif building == SFCRoom::Buildings::Tau && m = q.match(/([23][f階])?(ロフト|loft)/)
      if m[1]
        number = "#{m[1][0,1]}0"
        floor = m[1][0,1]
      else
        number = "20"
        floor = "2"
      end
    elsif building == SFCRoom::Buildings::Nu && m = q.match(/iij|docomo|ドコモ|舘内|森|dnp/i)
      if q.match(/iij/i)
        floor = SFCRoom::Floors::IIJHouse
      elsif q.match(/docomo|ドコモ/i)
        floor = SFCRoom::Floors::DocomoHouse
      elsif q.match(/dnp/i)
        floor = SFCRoom::Floors::DNPHouse
      elsif q.match(/舘内/i)
        floor = SFCRoom::Floors::TateuchiHouse
      elsif q.match(/森/i)
        floor = SFCRoom::Floors::MoriAtelier
      end
    elsif m = q.match(/(\d+)/)
      number = m[1]
      floor = m[1][0,1]
    end

    return Room.new building,number,floor
  end
  module_function :parse
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sfc-room-0.0.1 lib/sfc-room/parse.rb