Class: Mirrored::Date

Inherits:
Base
  • Object
show all
Defined in:
lib/mirrored/date.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

api_url, connection, establish_connection, remove_connection, service, valid_service?

Instance Attribute Details

#countObject

Returns the value of attribute count.



24
25
26
# File 'lib/mirrored/date.rb', line 24

def count
  @count
end

#dateObject

Returns the value of attribute date.



24
25
26
# File 'lib/mirrored/date.rb', line 24

def date
  @date
end

Class Method Details

.find(*args) ⇒ Object

Does all the hard work finding the dates you have posted and how many posts on those days.

Usage:

Mirrored::Date.find(:all)                 # => finds all dates you have posted with counts for each day
Mirrored::Date.find(:all, :tag => 'ruby') # => finds all dates you have posted something tagged ruby with counts for each day

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
# File 'lib/mirrored/date.rb', line 15

def self.find(*args)
  raise ArgumentError, "First argument must be symbol (:all)" unless args.first.kind_of?(Symbol)
  params = args.extract_options!
  params = params == {} ? nil : params
  
  doc = Hpricot::XML(connection.get("posts/dates", params))
  (doc/:date).inject([]) { |elements, el| elements << new_from_xml(el); elements }
end

.new_from_xml(xml) ⇒ Object

:nodoc:



3
4
5
6
7
8
# File 'lib/mirrored/date.rb', line 3

def self.new_from_xml(xml) #:nodoc:
  d       = Date.new
  d.date  = ::Date.parse((xml)['date'])
  d.count = (xml)['count']
  d
end