Class: Helipad::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/helipad.rb

Overview

Contains the properties and data that make up a Helipad document.

Various Helipad methods create and return Helipad::Document objects; there is probably little reason to make an instance of Helipad::Document in your own code.

The class contains a number of read-only methods for retrieving a document’s properties. Depending on which Helipad method created the Helipad::Document object, some of these methods may not be present. For example, the Helipad.get_titles method leaves out the source attribute.

  • doc_id - ID of the document

  • title - Title of the document

  • source - Body of the document. Helipad understands Textile markup, which you can use to format the document’s text.

  • tags - An Array containing the document’s tags, each of which is a String

  • created_on - A DateTime object containing the creation time of the document

  • updated_on - A DateTime object containing the document’s last modification time

  • share - The URL where the document is shared, or nil if the document is not shared

  • approved? - true if the document contains a plugin approved by Helipad staff; false otherwise.

  • dangerous? - I don’t know what this means, but it’s true if the document’s “dangerous” property is true, and false otherwise.

  • raw_response - The raw XML response returned by Helipad. This could be useful if, for some reason, you want to parse the results yourself. See the Helipad API documentation for more information.

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Document

:nodoc:



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/helipad.rb', line 249

def initialize(source) #:nodoc:
  if source.kind_of? REXML::Element
    doc = REXML::Document.new(source.to_s)
  else
    doc = REXML::Document.new(source)
  end
  REXML::XPath.match(doc, "document/*").each do |tag|
    suffix = ""
    case tag.name
    when "approved"
      name = "approved"
      suffix = "?"
      value = tag.text == "true" ? true : false
    when "created-on"
      name = "created_on"
      value = DateTime.parse tag.text
    when "dangerous"
      name = "dangerous"
      suffix = "?"
      value = tag.text == "true" ? true : false
    when "share"
      name = "share"
      if tag.attributes["nil"] == "true"
        value = nil
      else
        value = "http://pad.helicoid.net/document/public/#{tag.text}"
      end
    when "source"
      name = "source"
      value = tag.text
    when "title"
      name = "title"
      value = tag.text
    when "updated-on"
      name = "updated_on"
      value = DateTime.parse tag.text
    when "id"
      name = "doc_id"
      value = Integer(tag.text)
    when "tags"
      name = "tags"
      value = Array.new
      REXML::XPath.match(tag, "tag/name/child::text()").each do |this_tag|
        value.push this_tag.to_s
      end
    else
      name = tag.name
      value = tag.text
    end
    self.instance_eval %{
      def self.#{name}#{suffix}
        @#{name}
      end
      @#{name} = value
    }, __FILE__, __LINE__
  end
  self.instance_eval %{
    def self.raw_response
      @raw_response
    end
    @raw_response = %{#{source}}
  }, __FILE__, __LINE__
end