Module: FbGraph::Page::CategoryAttributes

Included in:
FbGraph::Page
Defined in:
lib/fb_graph/page/category_attributes.rb

Constant Summary collapse

@@attributes =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



64
65
66
# File 'lib/fb_graph/page/category_attributes.rb', line 64

def self.included(klass)
  klass.alias_method_chain :initialize, :category_specific_attributes
end

Instance Method Details

#initialize_with_category_specific_attributes(identifier, attributes = {}) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/fb_graph/page/category_attributes.rb', line 68

def initialize_with_category_specific_attributes(identifier, attributes = {})
  initialize_without_category_specific_attributes identifier, attributes
  @@attributes[:raw].each do |key|
    self.send :"#{key}=", attributes[key]
  end
  @@attributes[:symbols].each do |key|
    self.send :"#{key}=", []
    if attributes[key]
      self.send :"#{key}=", attributes[key].keys.collect(&:to_sym)
    end
  end
  @@attributes[:date].each do |key|
    if attributes[key]
      value = Date.parse(attributes[key]) rescue attributes[key]
      self.send :"#{key}=", value
    end
  end
  @checkin_count = attributes[:checkins]
  @hours = {}
  if attributes[:hours]
    utc_beginning_of_day = Time.now.utc.beginning_of_day
    attributes[:hours].each do |key, value|
      date, index, mode = key.split('_')
      index = index.to_i - 1
      date, mode = date.to_sym, mode.to_sym
      time = value.since(utc_beginning_of_day)
      time = Time.utc(1970, 1, 1, time.hour, time.min)
      @hours[date] ||= []
      @hours[date][index] ||= {}
      @hours[date][index][mode] = time
    end
  end
  if attributes[:location]
    @location = Venue.new(attributes[:location])
  end
end