Class: Pdfmdshow
Overview
Class: pdfmd.show
Constant Summary collapse
- @@show_filename =
false
- @@outputformat =
''
['createdate', 'author', 'title', 'subject', 'keywords']
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
Attributes inherited from Pdfmd
Instance Method Summary collapse
-
#initialize(filename) ⇒ Pdfmdshow
constructor
A new instance of Pdfmdshow.
-
#set_outputformat(format = 'yaml') ⇒ Object
Define the output format for showing the metadata.
-
#set_tags(tags = @@default_tags) ⇒ Object
Overvwrite the tags.
-
#show_filename(enable = nil) ⇒ Object
Define if the filename should be visible in the output.
-
#show_metatags(tags = @@default_tags, format = @@outputformat, show_filename = @@show_filename) ⇒ Object
Return the provided metatags.
Methods inherited from Pdfmd
#check_metatags, #metadata, #readUserInput, #read_metatags
Methods included from Pdfmdmethods
#determineValidSetting, #log, #queryHiera
Constructor Details
#initialize(filename) ⇒ Pdfmdshow
Returns a new instance of Pdfmdshow.
10 11 12 13 |
# File 'lib/pdfmd/pdfmdshow.rb', line 10 def initialize(filename) super(filename) @filename = filename end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
4 5 6 |
# File 'lib/pdfmd/pdfmdshow.rb', line 4 def filename @filename end |
Instance Method Details
#set_outputformat(format = 'yaml') ⇒ Object
Define the output format for showing the metadata
23 24 25 26 27 |
# File 'lib/pdfmd/pdfmdshow.rb', line 23 def set_outputformat( format = 'yaml' ) format.nil? ? format = 'yaml' : '' self.log('debug',"Output format set to '#{format}'.") @@outputformat = format end |
#set_tags(tags = @@default_tags) ⇒ Object
Overvwrite the tags
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pdfmd/pdfmdshow.rb', line 30 def ( = @@default_tags) if # Tags can be specified as array or string # case .class.to_s when /array/i @@default_tags = when /string/i @@default_tags = .split(/,\s+/) end end end |
#show_filename(enable = nil) ⇒ Object
Define if the filename should be visible in the output
17 18 19 |
# File 'lib/pdfmd/pdfmdshow.rb', line 17 def show_filename( enable = nil) @@show_filename = enable ? true : false end |
#show_metatags(tags = @@default_tags, format = @@outputformat, show_filename = @@show_filename) ⇒ Object
Return the provided metatags
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 |
# File 'lib/pdfmd/pdfmdshow.rb', line 48 def ( = @@default_tags, format = @@outputformat, show_filename = @@show_filename ) # Build the output hash from the tags matching the values in @@default_tags = Hash.new .each do |tagname| if @@metadata.has_key?(tagname) [tagname] = @@metadata[tagname] elsif tagname.downcase == 'all' # Exception when for keyword 'all' = @@metadata end end if show_filename ['filename'] = @filename end # Return output well formatted case format when /hash/i self.log('info',"Showing metatags for '#{@filename}' in format 'hash'.") when /csv/i csvData = Hash.new .keys.each do |tagname| csvData[tagname] = '"' + [tagname.downcase].to_s.gsub(/"/,'""') + '"' end self.log('info',"Showing metatags for '#{@filename}' in format 'csv'.") csvData.values.join(',') when /json/i require 'json' self.log('info',"Showing metatags for '#{@filename}' in format 'json'.") .to_json else require 'yaml' self.log('info',"Showing metatags for '#{@filename}' in format 'yaml'.") .to_yaml end end |