Class: QuickBase::Objects::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/QuickBaseObjects.rb

Overview

Definition of a Field built from the XML schema for a Table.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, type = nil, qbc = nil) ⇒ Field

Returns a new instance of Field.



63
64
65
66
67
68
# File 'lib/QuickBaseObjects.rb', line 63

def initialize(name = nil,type = nil,qbc = nil)
  set_qbc(qbc) if qbc
  @name = name || "new_field"
  @name = @name.strip.gsub(" ","_")
  @type = type || "text"
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



61
62
63
# File 'lib/QuickBaseObjects.rb', line 61

def attributes
  @attributes
end

#nameObject (readonly)

Returns the value of attribute name.



61
62
63
# File 'lib/QuickBaseObjects.rb', line 61

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



61
62
63
# File 'lib/QuickBaseObjects.rb', line 61

def properties
  @properties
end

#qbcObject

Returns the value of attribute qbc.



62
63
64
# File 'lib/QuickBaseObjects.rb', line 62

def qbc
  @qbc
end

Instance Method Details

#addChoice(choice, qbc = nil) ⇒ Object



101
102
103
104
# File 'lib/QuickBaseObjects.rb', line 101

def addChoice(choice, qbc = nil)
   set_qbc(qbc) if qbc
   @qbc.fieldAddChoices( @dbid, @id, choice )
end

#build(field_xml, qbc) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/QuickBaseObjects.rb', line 73

def build(field_xml,qbc)
  @qbc = qbc
  @dbid = qbc.dbid.dup
  @id = field_xml.attributes["id"]
  @attributes = Attributes.new
  field_xml.attributes.each_attribute{|attribute|
    @attributes[attribute.expanded_name]=attribute.value
  }
  @properties = Properties.new
  @choices = FieldChoices.new
  fieldProc = proc { |element|
      if element.is_a?(REXML::Element) 
         if element.name == "choice"
           @choices << element.text
         else  
            @properties[element.name] = element.has_text? ? element.text : nil
         end
      end
  }
  @qbc.processChildElements(field_xml,true,fieldProc)
  @name = @properties["label"].strip.gsub(" ","_")
  @attributes.each{|key,value|
     self.class.send(:define_method,key){@attributes[key]}
  }
  @properties.each{|key,value|
     self.class.send(:define_method,key){@properties[key]}
  }
end

#removeChoice(choice, qbc = nil) ⇒ Object



105
106
107
108
# File 'lib/QuickBaseObjects.rb', line 105

def removeChoice(choice, qbc = nil)
  set_qbc(qbc) if qbc
  @qbc.fieldRemoveChoices(@dbid, fid, choice) 
end

#set_qbc(qbc) ⇒ Object



69
70
71
72
# File 'lib/QuickBaseObjects.rb', line 69

def set_qbc(qbc)
  @qbc = qbc
  @dbid = qbc.dbid.dup
end

#setProperties(new_properties) ⇒ Object



109
110
111
# File 'lib/QuickBaseObjects.rb', line 109

def setProperties(new_properties) 
   @properties.merge!(new_properties) if @qbc.setFieldProperties( @dbid, new_properties, @id )
end