Class: Grandstand::Post

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/grandstand/post.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extract_month(attribute) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'app/models/grandstand/post.rb', line 16

def extract_month(attribute)
  case configurations[Rails.env]['adapter'].to_sym
  when :sqlite, :sqlite3
    "strftime('%m', #{attribute})"
  when :postgre, :postgres, :postgresql
    "EXTRACT(month FROM #{attribute})"
  when :mysql
    "MONTH(#{attribute})"
  end
end

.extract_year(attribute) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'app/models/grandstand/post.rb', line 27

def extract_year(attribute)
  case configurations[Rails.env]['adapter'].to_sym
  when :sqlite, :sqlite3
    "strftime('%Y', #{attribute})"
  when :postgre, :postgres, :postgresql
    "EXTRACT(year FROM #{attribute})"
  when :mysql
    "YEAR(#{attribute})"
  end
end

Instance Method Details

#to_htmlObject



39
40
41
# File 'app/models/grandstand/post.rb', line 39

def to_html
  @to_html ||= Mustache.render(Grandstand::Template.post, as_json)
end