Method: GSGraph::Work#initialize
- Defined in:
- lib/gs_graph/work.rb
#initialize(attributes = {}) ⇒ Work
Returns a new instance of Work.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gs_graph/work.rb', line 7 def initialize(attributes = {}) @description = attributes[:description] if (employer = attributes[:employer]) @employer = Page.new(employer[:id], employer) end if (location = attributes[:location]) @location = Page.new(location[:id], location) end if (position = attributes[:position]) @position = Page.new(position[:id], position) end @projects = [] if attributes[:projects] attributes[:projects].each do |project| @projects << Project.new(project[:id], project) end end @with = [] if attributes[:with] attributes[:with].each do |user| @with << User.new(user[:id], user) end end if attributes[:start_date] && attributes[:start_date] != '0000-00' year, month = attributes[:start_date].split('-').collect(&:to_i) @start_date = if month.blank? || month == 0 Date.new(year) else Date.new(year, month) end end if attributes[:end_date] && attributes[:end_date] != '0000-00' year, month = attributes[:end_date].split('-').collect(&:to_i) @end_date = if month.blank? || month == 0 Date.new(year) else Date.new(year, month) end end end |