public
Description: A gem that provides a ruby wrapper around the tickspot.com api
Homepage: http://tickspot.com/api/
Clone URL: git://github.com/bricooke/tickspot-ruby.git
tickspot-ruby / lib / tickspot_entry.rb
100644 36 lines (32 sloc) 0.867 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class TickspotEntry
  def initialize(parsed)
    @hash = parsed
  end
  
  def id
    self.method_missing(:id)
  end
  
  def empty?
    if @hash["type"] == "array" && @hash["content"] == "\n"
      true
    else
      false
    end
  end
  
  def method_missing(method, *args)
    if @hash.has_key?(method.to_s.singularize)
      entry = @hash[method.to_s.singularize]
      if method.to_s.pluralize == method.to_s && entry.class == Array
        return entry.collect {|e| TickspotEntry.new(e)}
      else
        return entry[0] unless entry[0].class == Hash && entry[0].has_key?("content")
        return entry[0]["content"]
      end
    elsif @hash.has_key?(method.to_s)
      entry = @hash[method.to_s]
      return entry[0] unless entry[0].class == Hash && entry[0].has_key?("content")
      return entry[0]["content"]
    else
      super
    end
  end
end