Module: GSGraph::Page::CategoryAttributes

Included in:
GSGraph::Page
Defined in:
lib/gs_graph/page/category_attributes.rb

Constant Summary collapse

@@category_attributes =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



63
64
65
# File 'lib/gs_graph/page/category_attributes.rb', line 63

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

Instance Method Details

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



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
# File 'lib/gs_graph/page/category_attributes.rb', line 67

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
  if attributes[:location]
    @location = Venue.new(attributes[:location])
  end
end