Module: FbGraph::Page::CategoryAttributes

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

Constant Summary collapse

@@category_attributes =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object


62
63
64
# File 'lib/fb_graph/page/category_attributes.rb', line 62

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

Instance Method Details

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


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

def initialize_with_category_specific_attributes(identifier, attributes = {})
  initialize_without_category_specific_attributes identifier, attributes
  @@category_attributes[:raw].each do |key|
    self.send :"#{key}=", attributes[key]
  end

  @@category_attributes[:symbols].each do |key|
    self.send :"#{key}=", []
    if attributes[key]
      self.send :"#{key}=", attributes[key].keys.collect(&:to_sym)
    end
  end
  @@category_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
  @location = case attributes[:location]
  when Hash
    Venue.new(attributes[:location])
  when String
    # ignore such non-structured data
  end
end