# field.rb - field descriptors # # Copyright (C) 2002 Yoshinori K. Okuji # # This file is part of BugCommunicator. # # BugCommunicator is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # BugCommunicator is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with BugCommunicator; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA module BugCommunicator # The basic class. class Field def initialize(name, display_name, note, admin_only, searchable, constant, required) unless name.kind_of?(String) raise TypeError, "name must be a string" end if name.length > 16 raise TypeError, "name is too long" end @name = name unless display_name.kind_of?(String) raise TypeError, "display_name must be a string" end if display_name.length > 255 raise TypeError, "display_name is too long" end @display_name = display_name unless note.kind_of?(String) raise TypeError, "note must be a string" end if note.length > 255 raise TypeError, "note is too long" end @note = note @admin_only = if admin_only then true else false end @searchable = if searchable then true else false end @constant = if constant then true else false end @required = if required then true else false end end def admin_only=(bool) @admin_only = if bool then true else false end end def admin_only? @admin_only end def searchable=(bool) @searchable = if bool then true else false end end def searchable? @searchable end def constant=(bool) @constant = if bool then true else false end end def constant? @constant end def required=(bool) @required = if bool then true else false end end def required? @required end def ==(field) return false unless field.kind_of?(Field) @name == field.name and @display_name == field.display_name and @note == field.note and @admin_only == field.admin_only and @searchable == field.searchable and @constant == field.constant and @required == field.required end attr_accessor :name, :display_name, :note attr_reader :admin_only, :searchable, :constant, :required end # Selection field. class SelectionField < Field def initialize(name, display_name, note, admin_only, searchable, constant, required, keywords, always_set) unless keywords.kind_of?(Array) raise TypeError, "keywords must be an array" end if keywords.empty? raise TypeError, "keywords cannot be empty" end keywords.each do |k| unless k.kind_of?(String) raise TypeError, "keyword must be a string" end if k.length > 255 raise TypeError, "keyword is too long" end end @keywords = keywords @always_set = if always_set then true else false end super(name, display_name, note, admin_only, searchable, constant, required) end def always_set=(bool) if bool then true else false end end def always_set? @always_set end def ==(field) return false unless field.kind_of?(SelectionField) @keywords == field.keywords and @always_set == field.always_set and super(field) end attr_accessor :keywords attr_reader :always_set end # Text field. class TextField < Field def initialize(name, display_name, note, admin_only, searchable, constant, required, can_be_empty, multiple_lines, regexp, searched_by_default) @can_be_empty = if can_be_empty then true else false end @multiple_lines = if multiple_lines then true else false end unless regexp.nil? unless regexp.kind_of?(String) raise TypeError, "regexp must be a string" end if regexp.length > 255 raise TypeError, "regexp is too long" end if /\#\{/ =~ regexp raise TypeError, "regexp has a dangerous expression" end end @regexp = regexp @searched_by_default = if searched_by_default then true else false end super(name, display_name, note, admin_only, searchable, constant, required) end def can_be_empty=(bool) @can_be_empty = if bool then true else false end end def can_be_empty? @can_be_empty end def multiple_lines=(bool) @multiple_lines = if bool then true else false end end def multiple_lines? @multiple_lines end def searched_by_default=(bool) @searched_by_default = if bool then true else false end end def searched_by_default? @searched_by_default end def ==(field) return false unless field.kind_of?(TextField) @regexp == field.regexp and @can_be_empty == field.can_be_empty and @multiple_lines == field.multiple_lines and @searched_by_default == field.searched_by_default and super(field) end attr_accessor :regexp attr_reader :can_be_empty, :multiple_lines, :searched_by_default end end