Class: JsonResume::Reader

Inherits:
Object show all
Defined in:
lib/json_resume/reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_input, options) ⇒ Reader

Returns a new instance of Reader.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/json_resume/reader.rb', line 11

def initialize(json_input, options)
    output_type = options[:output_type] || "html" #default html, others latex, md
	@json_string = case json_input
             when /^(http|https|www)/ then RestClient.get(json_input)
				   when /\.json$/i then File.read(json_input)
				   else json_input
				   end
    @output_type = output_type
	begin
		@hash = JSON.parse(@json_string)
	rescue JSON::ParserError => e
		raise Exception, "Either you entered a file without .json extension or JSON string is wrong: "+e.message
	end
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



9
10
11
# File 'lib/json_resume/reader.rb', line 9

def hash
  @hash
end

Instance Method Details

#format!Object



26
27
28
29
30
31
32
33
34
# File 'lib/json_resume/reader.rb', line 26

def format!
  formatters = {
    :latex => JsonResume::FormatterLatex,
    :html => JsonResume::FormatterHtml,
    :markdown => JsonResume::FormatterMd,
  }
  type = @output_type.to_sym
  @hash = formatters[type].new(@hash).format.hash
end