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.



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

def count
  @count
end

#dateObject

Returns the value of attribute date.



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

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)


18
19
20
21
22
23
24
25
# File 'lib/mirrored/date.rb', line 18

def 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:



6
7
8
9
10
11
# File 'lib/mirrored/date.rb', line 6

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