Class: QuickBase::Objects::Field
- Inherits:
-
Object
- Object
- QuickBase::Objects::Field
- Defined in:
- lib/QuickBaseObjects.rb
Overview
Definition of a Field built from the XML schema for a Table.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#qbc ⇒ Object
Returns the value of attribute qbc.
Instance Method Summary collapse
- #addChoice(choice, qbc = nil) ⇒ Object
- #build(field_xml, qbc) ⇒ Object
-
#initialize(name = nil, type = nil, qbc = nil) ⇒ Field
constructor
A new instance of Field.
- #removeChoice(choice, qbc = nil) ⇒ Object
- #set_qbc(qbc) ⇒ Object
- #setProperties(new_properties) ⇒ Object
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
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
61 62 63 |
# File 'lib/QuickBaseObjects.rb', line 61 def attributes @attributes end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
61 62 63 |
# File 'lib/QuickBaseObjects.rb', line 61 def name @name end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
61 62 63 |
# File 'lib/QuickBaseObjects.rb', line 61 def properties @properties end |
#qbc ⇒ Object
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.]=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 |