Module: ResumeTools::TextReader::ClassMethods

Included in:
Resume
Defined in:
lib/resumetools/resume/text_reader.rb

Instance Method Summary collapse

Instance Method Details

#from_text(text) ⇒ Object

Builds a new Resume instance from text


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
# File 'lib/resumetools/resume/text_reader.rb', line 37

def from_text(text)
  parser = ResumeTools::ResumeGrammarParser.new
  result = parser.parse(text)
  
  if result.nil?
    raise ParseException.new(parser.failure_reason)
  end
  
  resume = ResumeTools::Resume.new
  current_section = nil
  current_period = nil
  
  result.elements.each do |element|
    case element.data_type
    when :item
      item = ::ResumeTools::Item.new(:text => element.value)
      if current_period
        current_period.add_item(item)
      elsif current_section
        current_section.add_item(item)
      end
    when :period
      current_period = ::ResumeTools::Period.new(:title => element.value)
      current_section.add_period(current_period) if current_section
    when :section
      current_period = nil # Reset period
      current_section = ::ResumeTools::Section.new(:title => element.value)
      resume.add_section(current_section)
    when :period_location
      current_period.location = element.value if current_period
    when :period_organization
      current_period.organization = element.value if current_period
    when :period_dates
      if current_period
        dates = element.value.split("to", 2).map { |d| d.strip }
        if dates.length == 1
          current_period.dtend = dates[0]
          current_period.dtstart = nil
        elsif dates.length == 2
          current_period.dtstart = dates[0]
          current_period.dtend = dates[1]
        end
      end
    when :paragraph
      current_section.para = element.value if current_section
    when :contact_name
      resume.full_name = element.value
    when :contact_telephone
      resume.telephone = element.value
    when :contact_email
      resume.email = element.value
    when :contact_address
      if resume.address1.blank?
        resume.address1 = element.value
      elsif resume.address2.blank?
        resume.address2 = element.value
      end
    when :contact_url
      resume.url = element.value
    end
  end
  
  resume
end