Module: CVTool::Files
- Defined in:
- lib/cv_tool/files.rb
Class Method Summary collapse
- .get_content(path_or_content) ⇒ Object
- .get_json_db(path) ⇒ Object
- .json?(str) ⇒ Boolean
- .open(path) ⇒ Object
Class Method Details
.get_content(path_or_content) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/cv_tool/files.rb', line 20 def get_content(path_or_content) content = path_or_content path = content.gsub('\'', '').strip if File.exist? path content = Files.open(path) end return URI.encode_www_form_component(content) end |
.get_json_db(path) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/cv_tool/files.rb', line 37 def get_json_db(path) if File.exist? path path = path.gsub('\'', '').strip json_parser = JsonParser.new(path) return json_parser.db else return nil end end |
.json?(str) ⇒ Boolean
30 31 32 33 34 35 |
# File 'lib/cv_tool/files.rb', line 30 def json?(str) result = JSON.parse(str) result.is_a?(Hash) || result.is_a?(Array) rescue JSON::ParserError, TypeError return false end |
.open(path) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cv_tool/files.rb', line 8 def open(path) result = "" if File.exist? path File.open path do |f| result = f.read end end result end |