Class: BurstStruct::Burst

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Burst


3
4
5
# File 'lib/yelp/burst_struct.rb', line 3

def initialize(hash = {})
  @hash = hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object


11
12
13
14
15
16
17
18
19
# File 'lib/yelp/burst_struct.rb', line 11

def method_missing(method_name, *arguments, &block)
  key = find_key(method_name)

  if key
    return_or_build_struct(key)
  else
    super
  end
end

Class Method Details

.convert_array(array) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/yelp/burst_struct.rb', line 25

def self.convert_array(array)
  array.map do |item|
    case item
    when Hash
      Burst.new(item)
    when Array
      Burst.convert_array(item)
    else
      item
    end
  end
end

Instance Method Details

#has_key?(method_name) ⇒ Boolean


42
43
44
# File 'lib/yelp/burst_struct.rb', line 42

def has_key?(method_name)
  !find_key(method_name).nil?
end

#keysObject


7
8
9
# File 'lib/yelp/burst_struct.rb', line 7

def keys
  @hash.keys
end

#respond_to?(method_name, include_private = false) ⇒ Boolean


21
22
23
# File 'lib/yelp/burst_struct.rb', line 21

def respond_to?(method_name, include_private = false)
  has_key?(method_name) || super
end

#to_json(options = {}) ⇒ Object


38
39
40
# File 'lib/yelp/burst_struct.rb', line 38

def to_json(options = {})
  JSON.generate(@hash)
end