Class: DataKitten::DistributionFormat
- Inherits:
-
Object
- Object
- DataKitten::DistributionFormat
- Defined in:
- lib/data_kitten/distribution_format.rb
Overview
A file format for a distribution
For instance CSV, XML, etc.
Instance Attribute Summary collapse
-
#extension ⇒ Symbol
A symbol for the file extension.
Instance Method Summary collapse
-
#initialize(distribution) ⇒ DistributionFormat
constructor
Create a new DistributionFormat object with the relevant extension.
-
#matches? ⇒ Boolean
Whether the format of the file matches the extension given by the data.
-
#open? ⇒ Boolean
Is this an open format?.
-
#structured? ⇒ Boolean
Is this a structured format?.
Constructor Details
#initialize(distribution) ⇒ DistributionFormat
Create a new DistributionFormat object with the relevant extension
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/data_kitten/distribution_format.rb', line 16 def initialize(distribution) @distribution = distribution # Store extension as a lowercase symbol @extension = distribution.extension.to_s.downcase.to_sym # Set up format lists @@formats ||= { csv: { structured: true, open: true }, xls: { structured: true, open: false }, xlsx: { structured: true, open: true }, rdf: { structured: true, open: true }, xml: { structured: true, open: true }, wms: { structured: true, open: true }, ods: { structured: true, open: true }, rdfa: { structured: true, open: true }, kml: { structured: true, open: true }, rss: { structured: true, open: true }, json: { structured: true, open: true }, ical: { structured: true, open: true }, sparql: { structured: true, open: true }, kml: { structured: true, open: true }, georss: { structured: true, open: true }, geojson: { structured: true, open: true }, shp: { structured: true, open: true }, html: { structured: false, open: true }, doc: { structured: false, open: false }, pdf: { structured: false, open: true }, } end |
Instance Attribute Details
#extension ⇒ Symbol
Returns a symbol for the file extension. For instance, :csv.
11 12 13 |
# File 'lib/data_kitten/distribution_format.rb', line 11 def extension @extension end |
Instance Method Details
#matches? ⇒ Boolean
Whether the format of the file matches the extension given by the data
62 63 64 65 66 67 68 69 70 |
# File 'lib/data_kitten/distribution_format.rb', line 62 def matches? begin mimes = [] MIME::Types.type_for(@extension.to_s).each { |i| mimes << i.content_type } !!(@distribution.http_head.content_type =~ /#{mimes.join('|')}/) || false rescue nil end end |
#open? ⇒ Boolean
Is this an open format?
55 56 57 |
# File 'lib/data_kitten/distribution_format.rb', line 55 def open? @@formats[@extension][:open] rescue nil end |
#structured? ⇒ Boolean
Is this a structured format?
48 49 50 |
# File 'lib/data_kitten/distribution_format.rb', line 48 def structured? @@formats[@extension][:structured] rescue nil end |