Class: TickspotEntry

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

Instance Method Summary collapse

Constructor Details

#initialize(parsed) ⇒ TickspotEntry

Returns a new instance of TickspotEntry.



2
3
4
# File 'lib/tickspot_entry.rb', line 2

def initialize(parsed)
  @hash = parsed
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tickspot_entry.rb', line 18

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

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
# File 'lib/tickspot_entry.rb', line 10

def empty?
  if @hash["type"] == "array" && @hash["content"] == "\n"
    true
  else
    false 
  end
end

#idObject



6
7
8
# File 'lib/tickspot_entry.rb', line 6

def id
  self.method_missing(:id)
end