カテゴリー別アーカイブ: Ruby

とろろのろとろのなんたらかんたら

前に貼った作りかけのコードが今こうなっている.

Rails を使ってみた. http://tororo-fmk.heroku.com/

# coding: UTF-8

class LotroChatdef
  @str = ''
  def make_filter(type, name = '')
    to = ''
    from = ''
    type_s = what_type?(type)
    if type_s == 'User' then
      return false if name == ''
      to   = to_channel(name, true)
      from = from_channel(name, true)
    elsif type_s == 'Tell' then
      to   = to_person
      from = from_person
    elsif type_s != false then
      to   = to_channel(type_s, false)
      from = from_channel(type_s, false)
    else
      return false
    end
    @str = to + "\n" + from
    return @str
  end
  def what_type?(type)
    if    /^u/i =~ type then
      return 'User'
    elsif /^te/i =~ type then
      return 'Tell'
    elsif /^f/i =~ type then
      return 'Fellowship'
    elsif /^k/i =~ type then
      return 'Kinship'
    elsif /^ra/i =~ type then
      return 'Raid'
    elsif /^g/i =~ type then
      return 'Group'
    elsif /^tr/i =~ type then
      return 'Tribe'
    else
      return false
    end
  end
  def get_filter
    return @str
  end
  def to_channel(channel_name, ignore_casing)
    tmp = "/^\\[To #{channel_name}\\] /"
    tmp += 'i' if ignore_casing == true
    tmp += "\t"
    return tmp
  end
  def to_person
    return "/^You tell (.+?), /\t"
  end
  def from_channel(channel_name, ignore_casing)
    tmp = "/^\\[#{channel_name}\\] (.+?): /"
    tmp += 'i' if ignore_casing == true
    tmp += "\t"
    return tmp
  end
  def from_person
    return "/^(.+?) tells you, /\t"
  end
end

とろろのろとろ用フィルター生成ツールを作ろうかと思っている

ホワイトリストをお手軽に作るためのツール.Web で動作するようにしたいと思います.なんとなく作りかけのコードを貼り付けておきます.

# coding: UTF-8

class LotROChatDef
  def to_channel(channel_name, ignore_casing = true)
    tmp = "/^\\[To #{channel_name}\\] /"
    tmp += 'i' if ignore_casing == true
    return tmp
  end
  def to_fellowship
    return to_channel('Fellowship', false)
  end
  def to_kinship
    return to_channel('Kinship', false)
  end
  def to_person
    return '/^You tell (.+?), /'
  end
  def from_channel(channel_name, ignore_casing = true)
    tmp = "/^\\[#{channel_name}\\] (.+?): /"
    tmp += 'i' if ignore_casing == true
    return tmp
  end
  def from_fellowship
    return from_channel('Fellowship', false)
  end
  def from_kinship
    return from_channel('Kinship', false)
  end
  def from_person
    return '/^(.+?) tells you, /'
  end
end