Class: Sheng::CheckBox
- Inherits:
-
Object
- Object
- Sheng::CheckBox
- Defined in:
- lib/sheng/check_box.rb
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#xml_document ⇒ Object
readonly
Returns the value of attribute xml_document.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(element = nil) ⇒ CheckBox
constructor
A new instance of CheckBox.
- #interpolate(data_set) ⇒ Object
- #key ⇒ Object
- #raw_key ⇒ Object
- #value_is_truthy?(value) ⇒ Boolean
Constructor Details
#initialize(element = nil) ⇒ CheckBox
Returns a new instance of CheckBox.
11 12 13 14 15 |
# File 'lib/sheng/check_box.rb', line 11 def initialize(element = nil) @element = element @xml_document = element.document @errors = [] end |
Instance Attribute Details
#element ⇒ Object (readonly)
Returns the value of attribute element.
3 4 5 |
# File 'lib/sheng/check_box.rb', line 3 def element @element end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
3 4 5 |
# File 'lib/sheng/check_box.rb', line 3 def errors @errors end |
#xml_document ⇒ Object (readonly)
Returns the value of attribute xml_document.
3 4 5 |
# File 'lib/sheng/check_box.rb', line 3 def xml_document @xml_document end |
Class Method Details
.from_element(element) ⇒ Object
6 7 8 |
# File 'lib/sheng/check_box.rb', line 6 def from_element(element) new(element) end |
Instance Method Details
#==(other) ⇒ Object
17 18 19 |
# File 'lib/sheng/check_box.rb', line 17 def ==(other) other.is_a?(self.class) && other.element == element end |
#interpolate(data_set) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# 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 ⇒ Object
21 22 23 |
# File 'lib/sheng/check_box.rb', line 21 def key @element.xpath('.//w:name').first['w:val'] end |
#raw_key ⇒ Object
25 26 27 |
# File 'lib/sheng/check_box.rb', line 25 def raw_key key end |
#value_is_truthy?(value) ⇒ Boolean
41 42 43 |
# File 'lib/sheng/check_box.rb', line 41 def value_is_truthy?(value) ['true', '1', 'yes'].include? value.to_s.downcase end |