class Alfred::Feedback::Item
Constants
- ATTRIBUTES
Compatibility Note:
In Ruby 1.8, Object#type is defined, to workaround this the type attribute can be accessed via #item_type
- ATTRIBUTES_XML_MAP
- CHILD_NODES
Public Class Methods
new()
click to toggle source
# File lib/alfredlite/feedback.rb, line 35 def initialize @item_type = 'file' end
Private Class Methods
child_attribute_name(child_node, attribute)
click to toggle source
# File lib/alfredlite/feedback.rb, line 82 def self.child_attribute_name(child_node, attribute) "#{child_node}_#{attribute}" end
getter_unless_exists(attr)
click to toggle source
# File lib/alfredlite/feedback.rb, line 86 def self.getter_unless_exists(attr) getter = attr.to_sym attr_reader attr unless instance_method_exists?(getter) end
instance_method_exists?(method)
click to toggle source
generate getters and setters
# File lib/alfredlite/feedback.rb, line 74 def self.instance_method_exists?(method) # In Ruby 1.8, Object.instance_methods returns and array of strings # In Ruby 1.9+, it returns an array of symbols method = RUBY_VERSION < '1.9' ? method.to_s : method.to_sym instance_methods.include?(method) end
setter_unless_exists(attr)
click to toggle source
# File lib/alfredlite/feedback.rb, line 91 def self.setter_unless_exists(attr) setter = "#{attr}=".to_sym attr_writer attr unless instance_method_exists?(setter) end
Public Instance Methods
to_xml()
click to toggle source
# File lib/alfredlite/feedback.rb, line 43 def to_xml item_node = REXML::Element.new('item') ATTRIBUTES.each do |attrib| value = method(attrib).call xml_attrib = ATTRIBUTES_XML_MAP.fetch(attrib, attrib) #item_node[xml_attrib.to_s] = value unless value.nil? item_node.add_attribute(xml_attrib.to_s, value) unless value.nil? end CHILD_NODES.each do |node_name, node_attribs| value = method(node_name).call unless value.nil? item_node << REXML::Element.new(node_name.to_s).tap do |child| child.text = value node_attribs.each do |attrib| attr = self.class.child_attribute_name(node_name, attrib) value = method(attr).call child.add_attribute(attr, value) unless value.nil? end end end end item_node end
valid=(valid)
click to toggle source
# File lib/alfredlite/feedback.rb, line 39 def valid=(valid) @valid = valid ? 'true' : 'false' end