Class: MingleEvents::Feed::Entry
- Inherits:
-
Object
- Object
- MingleEvents::Feed::Entry
- Defined in:
- lib/mingle_events/feed/entry.rb
Overview
A Ruby wrapper around an Atom entry, particularly an Atom entry representing an event in Mingle.
Class Method Summary collapse
Instance Method Summary collapse
- #==(object) ⇒ Object
-
#author ⇒ Object
The user who created the entry (triggered the event), i.e., changed project data in Mingle.
-
#card? ⇒ Boolean
Whether the entry/event was sourced by a Mingle card.
-
#card_number ⇒ Object
The number of the card that sourced this entry/event.
-
#card_version_resource_uri ⇒ Object
The resource URI for the card version that was created by this event.
-
#categories ⇒ Object
The set of Atom categoies describing the entry.
-
#changes ⇒ Object
The array of changes for this entry.
-
#entry_id ⇒ Object
(also: #event_id)
The Atom entry’s id value.
- #eql?(object) ⇒ Boolean
-
#initialize(entry_element) ⇒ Entry
constructor
Construct with the wrapped Xml Elem for the entry.
- #links ⇒ Object
-
#raw_xml ⇒ Object
The raw entry XML from the Atom feed.
-
#title ⇒ Object
The Atom entry’s title.
- #to_s ⇒ Object
-
#updated ⇒ Object
The time at which entry was created, i.e., the event was triggered.
-
#version ⇒ Object
The version number of the card or page that was created by this event.
Constructor Details
#initialize(entry_element) ⇒ Entry
Construct with the wrapped Xml Elem for the entry
9 10 11 |
# File 'lib/mingle_events/feed/entry.rb', line 9 def initialize(entry_element) @entry_element = entry_element end |
Class Method Details
.from_snippet(entry_xml) ⇒ Object
13 14 15 |
# File 'lib/mingle_events/feed/entry.rb', line 13 def self.from_snippet(entry_xml) self.new(Xml.parse(entry_xml, ATOM_AND_MINGLE_NS).select('/atom:entry')) end |
Instance Method Details
#==(object) ⇒ Object
104 105 106 |
# File 'lib/mingle_events/feed/entry.rb', line 104 def ==(object) eql?(object) end |
#author ⇒ Object
The user who created the entry (triggered the event), i.e., changed project data in Mingle
40 41 42 |
# File 'lib/mingle_events/feed/entry.rb', line 40 def @author ||= Author.new(@entry_element.select("./atom:author")) end |
#card? ⇒ Boolean
Whether the entry/event was sourced by a Mingle card
62 63 64 |
# File 'lib/mingle_events/feed/entry.rb', line 62 def card? categories.any?{|c| c == Category::CARD} end |
#card_number ⇒ Object
The number of the card that sourced this entry/event. If the entry is not a card event an error will be thrown. The source of this data is perhaps not so robust and we’ll need to revisit this in the next release of Mingle.
69 70 71 72 |
# File 'lib/mingle_events/feed/entry.rb', line 69 def card_number raise "You cannot get the card number for an event that is not sourced by a card!" unless card? @card_number ||= parse_card_number end |
#card_version_resource_uri ⇒ Object
The resource URI for the card version that was created by this event. Throws error if not card event.
81 82 83 84 |
# File 'lib/mingle_events/feed/entry.rb', line 81 def card_version_resource_uri raise "You cannot get card version data for an event that is not sourced by a card!" unless card? @card_version_resource_uri ||= parse_card_version_resource_uri end |
#categories ⇒ Object
The set of Atom categoies describing the entry
45 46 47 48 49 |
# File 'lib/mingle_events/feed/entry.rb', line 45 def categories @categories ||= @entry_element.select_all("./atom:category").map do |category_element| Category.new(category_element.attr("term"), category_element.attr("scheme")) end end |
#changes ⇒ Object
The array of changes for this entry. Each change is a hash with redundant :type and :category entries specifying the category to which the change maps.
Change detail is contained in nested hashes with keys mapping exactly to the XML as described in www.thoughtworks-studios.com/mingle/3.3/help/mingle_api_events.html. The data in the change hashes reflect only what is in the XML as encriching them would require potentially many calls to the Mingle server resulting in very slow processing.
57 58 59 |
# File 'lib/mingle_events/feed/entry.rb', line 57 def changes @changes ||= Changes.new(@entry_element.select("./atom:content/mingle:changes")) end |
#entry_id ⇒ Object Also known as: event_id
The Atom entry’s id value. This is the one true identifier for the entry, and therefore the event.
24 25 26 |
# File 'lib/mingle_events/feed/entry.rb', line 24 def entry_id @entry_id ||= @entry_element.inner_text("./atom:id") end |
#eql?(object) ⇒ Boolean
94 95 96 97 98 99 100 101 102 |
# File 'lib/mingle_events/feed/entry.rb', line 94 def eql?(object) if object.equal?(self) return true elsif !self.class.equal?(object.class) return false end return object.entry_id == entry_id end |
#links ⇒ Object
86 87 88 |
# File 'lib/mingle_events/feed/entry.rb', line 86 def links Links.new(@entry_element) end |
#raw_xml ⇒ Object
The raw entry XML from the Atom feed
18 19 20 |
# File 'lib/mingle_events/feed/entry.rb', line 18 def raw_xml @raw_xml ||= @entry_element.raw_xml end |
#title ⇒ Object
The Atom entry’s title
30 31 32 |
# File 'lib/mingle_events/feed/entry.rb', line 30 def title @title ||= @entry_element.inner_text('./atom:title') end |
#to_s ⇒ Object
90 91 92 |
# File 'lib/mingle_events/feed/entry.rb', line 90 def to_s "Entry[entry_id=#{entry_id}, updated=#{updated}]" end |
#updated ⇒ Object
The time at which entry was created, i.e., the event was triggered
35 36 37 |
# File 'lib/mingle_events/feed/entry.rb', line 35 def updated @updated ||= Time.parse(@entry_element.inner_text("./atom:updated")) end |
#version ⇒ Object
The version number of the card or page that was created by this event. (For now, only working with cards.)
76 77 78 |
# File 'lib/mingle_events/feed/entry.rb', line 76 def version @version ||= CGI.parse(URI.parse(card_version_resource_uri).query)["version"].first.to_i end |