class Sheng::CheckBox

Attributes

element[R]
errors[R]
xml_document[R]

Public Class Methods

from_element(element) click to toggle source
# File lib/sheng/check_box.rb, line 6
def from_element(element)
  new(element)
end
new(element = nil) click to toggle source
# File lib/sheng/check_box.rb, line 11
def initialize(element = nil)
  @element = element
  @xml_document = element.document
  @errors = []
end

Public Instance Methods

==(other) click to toggle source
# File lib/sheng/check_box.rb, line 17
def ==(other)
  other.is_a?(self.class) && other.element == element
end
interpolate(data_set) click to toggle source
# File lib/sheng/check_box.rb, line 29
def interpolate(data_set)
  value = data_set.fetch(key)
  checked_attribute = @element.search('.//w:default').first.attribute('val')
  checked_attribute.value = value_is_truthy?(value) ? '1' : '0'
rescue DataSet::KeyNotFound => e
  @errors << e
  # Ignore this error; if the key for this checkbox is not found in the
  # data set, we don't want to uncheck the checkbox; we just want to leave
  # it alone.
  nil
end
key() click to toggle source
# File lib/sheng/check_box.rb, line 21
def key
  @element.xpath('.//w:name').first['w:val']
end
raw_key() click to toggle source
# File lib/sheng/check_box.rb, line 25
def raw_key
  key
end
value_is_truthy?(value) click to toggle source
# File lib/sheng/check_box.rb, line 41
def value_is_truthy?(value)
  ['true', '1', 'yes'].include? value.to_s.downcase
end