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



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

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

Instance Method Details

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



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
104
105
106
107
108
109
110
111
112
113
# File 'lib/fb_graph/page/category_attributes.rb', line 69

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|
    date = if attributes[key]
      begin
        Date.parse attributes[key]
      rescue
        attributes[key]
      end
    end
    self.send :"#{key}=", date
  end
  @checkin_count = attributes[:checkins]
  @hours = {}
  if attributes[:hours]
    attributes[:hours].each do |key, value|
      date, index, mode = key.split('_')
      index = index.to_i - 1
      date, mode = date.to_sym, mode.to_sym
      if value.class == Fixnum
        # The Unix "time" returned is a weird approximation of the string value.
        # Example: "20:00" might be represented as 446400, which is 1970-01-05T20:00:00-08:00
        time = Time.at(value).in_time_zone("Pacific Time (US & Canada)")
      else
        time = Time.parse(value)
      end
      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