Guest User

Untitled

a guest
Feb 21st, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. module Portfolio
  2. class Project < StaticModel::Base
  3. set_data_file File.join('data', 'projects.yml')
  4.  
  5. def to_s
  6. "#{title}"
  7. end
  8.  
  9. def category_classes
  10. classes = []
  11. classes.concat technologies.compact.collect {|t| "tech_#{t.gsub(' ', '_')}" }
  12. classes.concat features.compact.collect {|t| "feature_#{t.gsub(' ', '_')}" }
  13. classes << "year_#{launched_at.year}" if launched_at
  14. classes
  15. end
  16.  
  17. def description
  18. @attributes['description'] || ''
  19. end
  20.  
  21. def project_type
  22. @attributes['project_type'] || nil
  23. end
  24.  
  25. def launched_at
  26. launched ? Time.parse(launched) : false
  27. end
  28.  
  29. def launched
  30. @attributes['launched'] || false
  31. end
  32.  
  33. def links
  34. Array(@attributes['links']).collect do |l|
  35. link, link_text = l.split('|')
  36. link_text ||= link
  37. [link_text, link]
  38. end
  39. end
  40.  
  41. class << self
  42.  
  43. def technologies
  44. @technologies ||= self.all.collect {|p| p.technologies.compact }.flatten.uniq.sort
  45. end
  46.  
  47. def features
  48. @features ||= self.all.collect {|p| p.features.compact }.flatten.uniq.sort
  49. end
  50.  
  51. def years
  52. @years ||= self.all.collect {|p| p.launched_at.year if p.launched_at }.compact.uniq.sort
  53. end
  54. end
  55. end
  56. end
Add Comment
Please, Sign In to add comment