Sha256: 39504fb0b1afb90fa1862847a32867fbfe577fc5acb5152fd34d3044d43559c8

Contents?: true

Size: 1.78 KB

Versions: 12

Compression:

Stored size: 1.78 KB

Contents

module ResumeTools
  module Renderer
    class JSON
      def initialize(resume)
        @resume = resume
      end
      
      def render(opts={})
        frame = {
          :full_name => @resume.full_name,
          :url => @resume.url,
          :email => @resume.email,
          :telephone => @resume.telephone,
          :address1 => @resume.address1,
          :address2 => @resume.address2,
          :sections => @resume.sections.map { |section| section.json_frame }
        }
        ::JSON.generate(frame)
      end
    end
    
    module JSONHelpers
      module SectionMethods
        def json_frame
          frame = {
            :title => self.title,
            :para => self.para,
            :items => self.items.map { |item| item.json_frame },
            :periods => self.periods.map { |period| period.json_frame }
          }
        end
      end
      
      module ItemMethods
        def json_frame
          frame = { :text => self.text }
        end
      end
      
      module PeriodMethods
        def json_frame
          frame = {
            :title => self.title,
            :location => self.location,
            :organization => self.organization,
            :dtstart => self.dtstart,
            :dtend => self.dtend,
            :items => self.items.map { |item| item.json_frame }
          }
        end
      end
    end
    
    module JSONMethods
      def render_json(opts={})
        renderer = JSON.new(self)
        renderer.render(opts)
      end
    end
  end
  
  Section.class_eval do
    include Renderer::JSONHelpers::SectionMethods
  end
  
  Period.class_eval do
    include Renderer::JSONHelpers::PeriodMethods
  end
  
  Item.class_eval do
    include Renderer::JSONHelpers::ItemMethods
  end
  
  Resume.class_eval do
    include Renderer::JSONMethods
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
resumetools-1.1.0 lib/resumetools/resume/json.rb
resumetools-1.0.3 lib/resumetools/resume/json.rb
resumetools-1.0.2 lib/resumetools/resume/json.rb
resumetools-1.0.1 lib/resumetools/resume/json.rb
resumetools-1.0.0 lib/resumetools/resume/json.rb
resumetools-0.2.9.2 lib/resumetools/resume/json.rb
resumetools-0.2.9.1 lib/resumetools/resume/json.rb
resumetools-0.2.9.0 lib/resumetools/resume/json.rb
resumetools-0.2.8.5 lib/resumetools/resume/json.rb
resumetools-0.2.8.2 lib/resumetools/resume/json.rb
resumetools-0.2.8 lib/resumetools/resume/json.rb
resumetools-0.2.7.6 lib/resumetools/resume/json.rb