Class: Tickspot::Data

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

Instance Method Summary collapse

Constructor Details

#initialize(parsed) ⇒ Data

Returns a new instance of Data.



4
5
6
7
8
# File 'lib/tickspot/data.rb', line 4

def initialize(parsed)
  # @data = parsed
  # raise unless parsed.class == Hash
  @data = parsed#[parsed.keys.first]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

def empty?

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

end



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tickspot/data.rb', line 22

def method_missing(method, *args)
  puts "->#{method}, #{args}"
  return Data.new(@data[args.first]) if @data.class == Array
  if @data.has_key?(method.to_s)
    entry = @data[method.to_s]
    # return entry[0] unless entry[0].class == Hash && entry[0].has_key?("content")
    # return entry[0]["content"]
    # entry = Data.new(entry) if entry.class == Hash
    entry
  else
    super
  end
end

Instance Method Details

#idObject



10
11
12
# File 'lib/tickspot/data.rb', line 10

def id
  self.method_missing(:id)
end