Class: Rubyfocus::Item
- Inherits:
-
Object
- Object
- Rubyfocus::Item
- Includes:
- ConditionalExec, IDRef
- Defined in:
- lib/rubyfocus/items/item.rb
Overview
The Rubyfocus Item represents an item found in an Omnifocus XML file, and thus also any Omnifocus entity.
The Rubyfocus Item has a parent “document” as well as a series of properties determined by the XML file proper. You can pass an XML document at creation or leave it blank. You can always apply XML later using Item#apply_xml or Item#<<
By separating these two methods, we can also patch the object with another XML node, e.g. through an update. This is important!
Instance Attribute Summary collapse
-
#added ⇒ Object
Returns the value of attribute added.
-
#document ⇒ Object
Returns the value of attribute document.
-
#id ⇒ Object
Returns the value of attribute id.
-
#modified ⇒ Object
Returns the value of attribute modified.
Instance Method Summary collapse
- #apply_xml(n) ⇒ Object (also: #<<)
-
#initialize(document = nil, n = nil) ⇒ Item
constructor
A new instance of Item.
-
#inspect ⇒ Object
————————————— Inspection method.
- #to_serial ⇒ Object
Methods included from ConditionalExec
Methods included from IDRef
Constructor Details
#initialize(document = nil, n = nil) ⇒ Item
Returns a new instance of Item.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rubyfocus/items/item.rb', line 15 def initialize(document=nil, n=nil) self.document = document case n when Nokogiri::XML::Element apply_xml(n) when Hash n.each do |k,v| setter = "#{k}=" send(setter,v) if respond_to?(setter) end end end |
Instance Attribute Details
#added ⇒ Object
Returns the value of attribute added.
13 14 15 |
# File 'lib/rubyfocus/items/item.rb', line 13 def added @added end |
#document ⇒ Object
Returns the value of attribute document.
13 14 15 |
# File 'lib/rubyfocus/items/item.rb', line 13 def document @document end |
#id ⇒ Object
Returns the value of attribute id.
13 14 15 |
# File 'lib/rubyfocus/items/item.rb', line 13 def id @id end |
#modified ⇒ Object
Returns the value of attribute modified.
13 14 15 |
# File 'lib/rubyfocus/items/item.rb', line 13 def modified @modified end |
Instance Method Details
#apply_xml(n) ⇒ Object Also known as: <<
29 30 31 32 33 |
# File 'lib/rubyfocus/items/item.rb', line 29 def apply_xml(n) self.id ||= n["id"] # This should not change once set! conditional_set(:added, n.at_xpath("xmlns:added")) { |e| Time.parse(e) } conditional_set(:modified, n.at_xpath("xmlns:modified")) { |e| Time.parse(e) } end |
#inspect ⇒ Object
Inspection method
39 40 41 42 |
# File 'lib/rubyfocus/items/item.rb', line 39 def inspect msgs = inspect_properties.select{ |sym| self.respond_to?(sym) && !self.send(sym).nil? } "#<#{self.class} " + msgs.map{ |e| %|#{e}=#{self.send(e).inspect}| }.join(" ") + ">" end |
#to_serial ⇒ Object
44 45 46 |
# File 'lib/rubyfocus/items/item.rb', line 44 def to_serial inspect_properties.each_with_object({}){ |s,hsh| hsh[s] = self.send(s) } end |