Module: KuaiJieQian::Utils
- Defined in:
- lib/kuai_jie_qian/utils.rb
Class Method Summary collapse
- .html_to_pdf(html_file_stream) ⇒ Object
- .pdf_to_png(file) ⇒ Object
-
.symbolize_keys(hash) ⇒ Hash
把 hash 中的 key,都转化为 symbol 类型.
Class Method Details
.html_to_pdf(html_file_stream) ⇒ Object
19 20 21 22 |
# File 'lib/kuai_jie_qian/utils.rb', line 19 def self.html_to_pdf(html_file_stream) kit = PDFKit.new(html_file_stream) kit.to_pdf end |
.pdf_to_png(file) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/kuai_jie_qian/utils.rb', line 24 def self.pdf_to_png(file) pdf = Grim.reap(file) png = pdf[0].save(file.split(".").first + '.png', {:quality => 90, :alpha => "remove", :colorspace => "RGB"} ) end |
.symbolize_keys(hash) ⇒ Hash
把 hash 中的 key,都转化为 symbol 类型
11 12 13 14 15 16 17 |
# File 'lib/kuai_jie_qian/utils.rb', line 11 def self.symbolize_keys(hash) new_hash = {} hash.each do |key, value| new_hash[(key.to_sym rescue key) || key] = value end new_hash end |