Class: XForms::Control

Inherits:
Object show all
Includes:
Label
Defined in:
lib/xforms/control.rb

Direct Known Subclasses

Input, Select1

Instance Attribute Summary collapse

Attributes included from Label

#label

Instance Method Summary collapse

Constructor Details

#initialize(form) ⇒ Control

Returns a new instance of Control.



49
50
51
52
# File 'lib/xforms/control.rb', line 49

def initialize(form)
  @form = form
  @readonly = false
end

Instance Attribute Details

#bindingObject

Returns the value of attribute binding.



41
42
43
# File 'lib/xforms/control.rb', line 41

def binding
  @binding
end

#constraintObject

Returns the value of attribute constraint.



43
44
45
# File 'lib/xforms/control.rb', line 43

def constraint
  @constraint
end

#constraint_messageObject

Returns the value of attribute constraint_message.



44
45
46
# File 'lib/xforms/control.rb', line 44

def constraint_message
  @constraint_message
end

#formObject

Returns the value of attribute form.



40
41
42
# File 'lib/xforms/control.rb', line 40

def form
  @form
end

#readonlyObject

Returns the value of attribute readonly.



42
43
44
# File 'lib/xforms/control.rb', line 42

def readonly
  @readonly
end

#relevantObject

Returns the value of attribute relevant.



45
46
47
# File 'lib/xforms/control.rb', line 45

def relevant
  @relevant
end

#typeObject

Returns the value of attribute type.



46
47
48
# File 'lib/xforms/control.rb', line 46

def type
  @type
end

Instance Method Details

#relevant?Boolean

Returns:

  • (Boolean)


79
80
81
82
# File 'lib/xforms/control.rb', line 79

def relevant?
  return true unless @relevant
  @relevant.dyn_value
end

#valid?Boolean

Returns:

  • (Boolean)


73
74
75
76
77
# File 'lib/xforms/control.rb', line 73

def valid?
  return true unless constraint
  node = form.model_instance.xpath(binding).first
  node.xpath(constraint) == true
end

#valueObject



59
60
61
62
63
64
65
66
67
# File 'lib/xforms/control.rb', line 59

def value
  data = form.model_instance.xpath(binding).first.inner_text
  return data unless type

  case type
  when 'int' then Integer(data) rescue 0
  else data
  end
end

#value=(value) ⇒ Object



54
55
56
57
# File 'lib/xforms/control.rb', line 54

def value=(value)
  value = Integer(value).to_s if type == 'int'
  form.model_instance.xpath(binding).first.children = value
end