Class: Jobless::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/document.rb

Constant Summary collapse

PERSONAL_ATTRIBUTES =
%w(
  name
  email
  location
  address
  homepage
)
GROUP_NAMES =
%w(
  employment
  education
  open_source
  other_experience
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocument

Returns a new instance of Document.



23
24
25
26
27
28
# File 'lib/document.rb', line 23

def initialize
  @data = {}
  @groups = []
  @template = File.expand_path("../template/template.html.erb", __FILE__)
  @stylesheet = File.expand_path("../template/style.css", __FILE__)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/document.rb', line 6

def data
  @data
end

#groupsObject (readonly)

Returns the value of attribute groups.



6
7
8
# File 'lib/document.rb', line 6

def groups
  @groups
end

Instance Method Details

#cssObject



61
62
63
# File 'lib/document.rb', line 61

def css
  File.read(@stylesheet)
end

#group(name, &block) ⇒ Object



41
42
43
44
45
# File 'lib/document.rb', line 41

def group(name, &block)
  group = Group.new(name)
  group.instance_eval &block
  @groups.push group
end

#stylesheet(file_path) ⇒ Object



57
58
59
# File 'lib/document.rb', line 57

def stylesheet(file_path)
  @stylesheet = file_path
end

#template(template) ⇒ Object



53
54
55
# File 'lib/document.rb', line 53

def template(template)
  @template = template
end

#write_to_file(filename) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/document.rb', line 65

def write_to_file(filename)
  renderer = ERB.new(File.read(@template))
  generated_html = renderer.result(binding)
  File.open(filename, 'w') do |file|
    file.write(generated_html)
  end
end